"""ProactiveScope — L1/L2 memory isolation for proactive chat."""

from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from typing import Any

from niannian.memory.space import memory_space_for_chat_mode
from niannian.users.paths import user_root
from niannian.virtual_persona.store import vp_proactive_profile_path


@dataclass(frozen=True)
class ProactivePersonaPolicy:
    """Stub for VP personality curves — full parsing in PC11-M10."""

    clinginess: float = 0.5
    self_disclosure: float = 0.5
    user_future_care: float = 0.5
    interruptiveness: float = 0.5


@dataclass(frozen=True)
class ProactiveScope:
    primary_project: str
    wiki_namespace: str
    profile_path: Path
    chat_mode: str
    vp_id: str | None


def resolve_proactive_scope(
    session_meta: dict[str, Any] | None,
    chat_mode: str,
    home: Path,
    user_id: str,
) -> ProactiveScope:
    meta = session_meta or {}
    mode_key = str(chat_mode or "auto").strip().lower()
    root = user_root(home, user_id)

    vp_id_raw = meta.get("equipped_vp_id")
    if vp_id_raw:
        vp_id = str(vp_id_raw).strip()
        return ProactiveScope(
            primary_project=f"vp:{vp_id}",
            wiki_namespace=f"vp/{vp_id}",
            profile_path=vp_proactive_profile_path(home, user_id, vp_id),
            chat_mode=mode_key,
            vp_id=vp_id,
        )

    memory_space = memory_space_for_chat_mode(mode_key)
    return ProactiveScope(
        primary_project=memory_space,
        wiki_namespace=f"mode/{memory_space}",
        profile_path=root / "proactive" / "mode" / f"{memory_space}.json",
        chat_mode=mode_key,
        vp_id=None,
    )
