import uuid
from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

from api.models.suggestion import SuggestionStage


class SuggestionNoteRead(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    suggestion_id: uuid.UUID
    stage: str
    author: str | None = None
    content: str
    created_at: datetime


class SuggestionRead(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: uuid.UUID
    domain_id: uuid.UUID
    domain_slug: str = ""
    topic_id: uuid.UUID | None = None
    workplan_id: uuid.UUID | None = None
    title: str
    description: str | None = None
    origin: str | None = None
    origin_ref: str | None = None
    stage: SuggestionStage
    relevance: int
    relevance_events: int
    last_requested_at: datetime | None = None
    base_value: float
    job_size: float
    relevance_weight: float
    promoted_task_id: uuid.UUID | None = None
    cost_of_delay: float | None = None
    wsjf: float | None = None
    created_at: datetime
    updated_at: datetime
    notes: list[SuggestionNoteRead] = Field(default_factory=list)


class SuggestionCreate(BaseModel):
    domain: str
    title: str
    description: str | None = None
    topic_id: uuid.UUID | None = None
    workplan_id: uuid.UUID | None = None
    origin: str | None = None
    origin_ref: str | None = None
    base_value: float = 3.0
    job_size: float = 3.0
    relevance_weight: float = 1.0


class SuggestionVet(BaseModel):
    author: str | None = None
    note: str
    base_value: float | None = None
    job_size: float | None = None
    relevance_weight: float | None = None
    workplan_id: uuid.UUID | None = None


class SuggestionDecline(BaseModel):
    author: str | None = None
    note: str


class SuggestionPromote(BaseModel):
    author: str | None = None
    note: str | None = None
    task_title: str | None = None
    task_description: str | None = None
    task_priority: str = "medium"
    task_status: str = "wait"


class SuggestionBumpRelevance(BaseModel):
    reason: str | None = None
    author: str | None = None


class RankedSuggestionDigest(BaseModel):
    id: uuid.UUID
    title: str
    stage: SuggestionStage
    domain_slug: str
    origin_ref: str | None = None
    relevance: int
    wsjf: float
    last_requested_at: datetime | None = None