from datetime import datetime

from pydantic import BaseModel, ConfigDict, EmailStr, Field


class ContactBase(BaseModel):
    account_id: int | None = None
    supplier_id: int | None = None
    first_name: str = Field(..., min_length=1, max_length=120)
    last_name: str | None = Field(None, max_length=120)
    job_title: str | None = Field(None, max_length=120)
    department: str | None = Field(None, max_length=120)
    area: str | None = Field(None, max_length=120)
    email: EmailStr | None = None
    phone: str | None = Field(None, max_length=40)
    extension: str | None = Field(None, max_length=20)
    mobile: str | None = Field(None, max_length=40)
    whatsapp: str | None = Field(None, max_length=40)
    is_primary: bool = False
    receives_quotes: bool = False
    receives_invoices: bool = False
    receives_commercial_info: bool = False
    status: str = Field("active", max_length=20)
    owner_user_id: str | None = Field(None, max_length=64)
    notes: str | None = None


class ContactCreate(ContactBase):
    pass


class ContactUpdate(BaseModel):
    account_id: int | None = None
    supplier_id: int | None = None
    first_name: str | None = Field(None, min_length=1, max_length=120)
    last_name: str | None = Field(None, max_length=120)
    job_title: str | None = Field(None, max_length=120)
    department: str | None = Field(None, max_length=120)
    area: str | None = Field(None, max_length=120)
    email: EmailStr | None = None
    phone: str | None = Field(None, max_length=40)
    extension: str | None = Field(None, max_length=20)
    mobile: str | None = Field(None, max_length=40)
    whatsapp: str | None = Field(None, max_length=40)
    is_primary: bool | None = None
    receives_quotes: bool | None = None
    receives_invoices: bool | None = None
    receives_commercial_info: bool | None = None
    status: str | None = Field(None, max_length=20)
    owner_user_id: str | None = Field(None, max_length=64)
    notes: str | None = None


class ContactResponse(ContactBase):
    model_config = ConfigDict(from_attributes=True)

    id: int
    tenant_id: int
    company_id: int
    created_at: datetime
    updated_at: datetime
