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


class FlagDefCreate(BaseModel):
    name: str
    emoji: Optional[str] = None
    color: Optional[str] = "#6b7280"
    text_color: Optional[str] = None
    sort_order: Optional[int] = 0


class FlagDefUpdate(BaseModel):
    name: Optional[str] = None
    emoji: Optional[str] = None
    color: Optional[str] = None
    text_color: Optional[str] = None
    sort_order: Optional[int] = None
    is_active: Optional[bool] = None


class FlagDefOut(BaseModel):
    id: int
    name: str
    emoji: Optional[str] = None
    color: Optional[str] = None
    text_color: Optional[str] = None
    sort_order: int
    is_active: bool

    model_config = {"from_attributes": True}


class FlagAssignmentOut(BaseModel):
    id: int
    table_id: int
    flag_id: int
    flag_def: Optional[FlagDefOut] = None
    assigned_at: datetime
    assigned_by: Optional[int] = None

    model_config = {"from_attributes": True}


class SetTableFlagsRequest(BaseModel):
    flag_ids: List[int]
