from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime


class ClientBase(BaseModel):
    name: str


class ClientCreate(ClientBase):
    pass


class ClientOut(ClientBase):
    id: int
    color: str

    class Config:
        from_attributes = True


class DealBase(BaseModel):
    name: str
    client_id: int
    status: str = "active"


class DealCreate(DealBase):
    pass


class DealOut(DealBase):
    id: int
    shade_index: int

    class Config:
        from_attributes = True


class ColumnBase(BaseModel):
    name: str
    sort_order: int = 0


class ColumnCreate(ColumnBase):
    pass


class ColumnOut(ColumnBase):
    id: int

    class Config:
        from_attributes = True


class TaskBase(BaseModel):
    title: str
    client_id: Optional[int] = None
    deal_id: Optional[int] = None
    column_id: Optional[int] = None
    due_date: Optional[str] = None
    is_quick: bool = False
    assignee: Optional[str] = None
    waiting_on: Optional[str] = None
    notes: Optional[str] = None
    master_priority: float = 0.0
    column_priority: float = 0.0


class TaskCreate(TaskBase):
    pass


class TaskUpdate(BaseModel):
    title: Optional[str] = None
    client_id: Optional[int] = None
    deal_id: Optional[int] = None
    column_id: Optional[int] = None
    due_date: Optional[str] = None
    is_quick: Optional[bool] = None
    assignee: Optional[str] = None
    waiting_on: Optional[str] = None
    notes: Optional[str] = None
    master_priority: Optional[float] = None
    column_priority: Optional[float] = None
    completed_at: Optional[str] = None


class TaskOut(TaskBase):
    id: int
    completed_at: Optional[str] = None
    created_at: Optional[str] = None

    class Config:
        from_attributes = True


class TemplateItem(BaseModel):
    title: str
    column_id: Optional[int] = None
    is_quick: bool = False


class TemplateBase(BaseModel):
    name: str
    items: List[TemplateItem]


class TemplateCreate(TemplateBase):
    pass


class TemplateOut(TemplateBase):
    id: int

    class Config:
        from_attributes = True
