"""Job Brief model — pre-approved work order submitted before job creation."""
from datetime import datetime
from enum import StrEnum

from pydantic import BaseModel, Field

from .job import RequestedOutputs


class BriefStatus(StrEnum):
    DRAFT = "draft"
    SUBMITTED = "submitted"
    APPROVED = "approved"
    REJECTED = "rejected"
    FULFILLED = "fulfilled"


class JobBrief(BaseModel):
    id: str | None = Field(None, alias="_id")
    organization_id: str
    project_id: str | None = None
    title: str
    description: str | None = None
    requested_outputs: RequestedOutputs
    languages: list[str] = []
    deadline: datetime | None = None
    status: BriefStatus = BriefStatus.DRAFT
    created_by: str
    job_id: str | None = None
    created_at: datetime = Field(default_factory=datetime.utcnow)
    updated_at: datetime = Field(default_factory=datetime.utcnow)
    submitted_at: datetime | None = None
    approved_by: str | None = None
    reject_reason: str | None = None

    class Config:
        populate_by_name = True


class JobBriefCreate(BaseModel):
    title: str
    description: str | None = None
    requested_outputs: RequestedOutputs
    languages: list[str] = []
    deadline: datetime | None = None
    project_id: str | None = None
    assignee_id: str | None = None
    source_has_ad: bool = False  # Source video already contains professional audio descriptions


class JobBriefUpdate(BaseModel):
    title: str | None = None
    description: str | None = None
    requested_outputs: RequestedOutputs | None = None
    languages: list[str] | None = None
    deadline: datetime | None = None


class JobBriefResponse(BaseModel):
    id: str
    organization_id: str
    project_id: str | None = None
    title: str
    description: str | None = None
    requested_outputs: RequestedOutputs
    languages: list[str]
    deadline: datetime | None = None
    status: BriefStatus
    created_by: str
    assignee_id: str | None = None
    job_id: str | None = None
    created_at: str
    updated_at: str
    submitted_at: str | None = None
    approved_by: str | None = None
