"""
Schemi Pydantic per PecContact (Feature 6 – Rubrica indirizzi PEC).
"""

import uuid
from datetime import datetime

from pydantic import BaseModel, EmailStr, field_validator


class PecContactCreate(BaseModel):
    email: EmailStr
    name: str | None = None
    organization: str | None = None
    notes: str | None = None
    is_favorite: bool = False

    @field_validator("email")
    @classmethod
    def email_lowercase(cls, v: str) -> str:
        return v.lower().strip()


class PecContactUpdate(BaseModel):
    name: str | None = None
    organization: str | None = None
    notes: str | None = None
    is_favorite: bool | None = None


class PecContactResponse(BaseModel):
    model_config = {"from_attributes": True}

    id: uuid.UUID
    tenant_id: uuid.UUID
    email: str
    name: str | None = None
    organization: str | None = None
    notes: str | None = None
    is_favorite: bool
    auto_saved: bool
    created_by: uuid.UUID | None = None
    created_at: datetime
    updated_at: datetime


class PecContactListResponse(BaseModel):
    items: list[PecContactResponse]
    total: int


class PecContactImportResult(BaseModel):
    created: int
    updated: int
    skipped: int
    errors: list[str] = []
