from pydantic import BaseModel
from typing import Optional

class ChatRequest(BaseModel):
    message: str
    session_id: str
    persona_id: Optional[str] = "default"
    is_narrator_choice: bool = False
    skip_user_add: bool = False
    first_mes_override: Optional[str] = None
    # After arc completion: "user" = injection only, player speaks next;
    # "character" = injection then character opens the new arc.
    new_arc_first: Optional[str] = None


class MessageEditRequest(BaseModel):
    content: str
    truncate_after: bool = False


class RegenerateRequest(BaseModel):
    session_id: str
    persona_id: Optional[str] = "default"
    message_id: Optional[int] = None


class ForkSessionRequest(BaseModel):
    until_message_id: int


class RebindPersonaRequest(BaseModel):
    persona_id: str
    clear_history: bool = False


class QuestStatusPatch(BaseModel):
    status: str


class RpgStateDebugPatch(BaseModel):
    """Debug override for relationship/stats (session-scoped to current player for now)."""
    affinity: Optional[int] = None
    lust: Optional[int] = None
    stamina: Optional[int] = None
    tension: Optional[int] = None


class SessionContextPatch(BaseModel):
    """Live-edit RPG / SD context fields for the active session."""
    status_quo: Optional[str] = None
    global_plot: Optional[str] = None
    outfit_json: Optional[str] = None
    scene_json: Optional[str] = None
    facts_json: Optional[str] = None
    plot_arc_json: Optional[str] = None
    affinity: Optional[int] = None
    lust: Optional[int] = None
    stamina: Optional[int] = None
    tension: Optional[int] = None

class ChatResponse(BaseModel):
    reply: str
    session_id: str
    image_prompt: Optional[str] = None

class PersonaCreate(BaseModel):
    persona_id: str
    name: str
    emoji: str = "🤖"
    description: str = ""
    prompt: str = ""
    sd_enabled: bool = False
    lora_name: str = ""
    lora_weight: float = 0.8
    appearance_tags: str = ""
    personality: str = ""
    scenario: str = ""
    first_mes: str = ""
    mes_example: str = ""
    lorebook_json: str = "[]"
    avatar_path: str = ""

class PersonaResponse(BaseModel):
    persona_id: str
    name: str
    emoji: str
    description: str
    prompt: str
    custom: bool = False
    sd_enabled: bool = False
    lora_name: str = ""
    lora_weight: float = 0.8
    appearance_tags: str = ""
    personality: str = ""
    scenario: str = ""
    first_mes: str = ""
    mes_example: str = ""
    lorebook_json: str = "[]"
    avatar_path: str = ""
