import uuid
from datetime import datetime

from pydantic import BaseModel, ConfigDict

from api.models.topic import TopicStatus


class TopicCreate(BaseModel):
    slug: str
    title: str
    description: str | None = None
    domain: str  # domain slug — resolved to domain_id in the router
    status: TopicStatus = TopicStatus.active


class TopicUpdate(BaseModel):
    title: str | None = None
    description: str | None = None
    status: TopicStatus | None = None
    domain: str | None = None  # domain slug — resolved to domain_id in the router


class WorkstreamStub(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    id: uuid.UUID
    slug: str
    title: str
    status: str
    owner: str | None = None
    due_date: datetime | None = None


class TopicRead(BaseModel):
    model_config = ConfigDict(from_attributes=True)
    id: uuid.UUID
    slug: str
    title: str
    description: str | None = None
    domain_slug: str | None = None  # resolved from FK relationship via @property
    status: TopicStatus
    created_at: datetime
    updated_at: datetime


class TopicWithWorkstreams(TopicRead):
    workstreams: list[WorkstreamStub] = []
