import uuid
from typing import Literal

from pydantic import BaseModel

from api.services.reconciliation import ReconciliationClass


TargetType = Literal["workstream", "task"]


class StateChangeRequest(BaseModel):
    target_type: TargetType
    target_id: uuid.UUID
    target_status: str
    actor: str = "dashboard"
    intent: str | None = None
    expected_current_status: str | None = None
    file_backed: bool | None = None
    archived_file: bool | None = None
    task_linked: bool | None = None
    tasks_terminal: bool | None = None
    blocking_reason: str | None = None
    apply: bool = False


class StateChangeResponse(BaseModel):
    target_type: TargetType
    target_id: uuid.UUID
    actor: str
    intent: str | None = None
    current_status: str
    target_status: str
    file_backed: bool
    archived_file: bool
    task_linked: bool | None = None
    tasks_terminal: bool | None = None
    reconciliation_class: ReconciliationClass
    reason: str
    follow_up: str
    write_through_result: Literal["not_attempted", "applied", "not_applicable"] = "not_attempted"
    workplan_path: str | None = None
    reconciliation_record_id: uuid.UUID | None = None
    conflict: bool = False
