import uuid
from datetime import datetime
from pydantic import BaseModel, Field


class CaldavCompanyConfigOut(BaseModel):
    model_config = {"from_attributes": True}
    id: uuid.UUID
    company_id: uuid.UUID
    enabled: bool
    principal_url: str
    calendar_url: str | None
    username: str
    calendar_display_name: str
    verify_ssl: bool
    name_template: str
    last_error: str | None
    updated_at: datetime


class CaldavCompanyConfigSave(BaseModel):
    enabled: bool = False
    principal_url: str = Field(min_length=1)
    calendar_url: str | None = None
    username: str = Field(min_length=1, max_length=255)
    password: str | None = None          # leer = unverändert
    calendar_display_name: str = ""
    verify_ssl: bool = True
    name_template: str = "$vorname $nachname – $typ"


class CaldavUserConfigOut(BaseModel):
    model_config = {"from_attributes": True}
    id: uuid.UUID
    user_id: uuid.UUID
    enabled: bool
    principal_url: str
    calendar_url: str | None
    username: str
    calendar_display_name: str
    verify_ssl: bool
    last_error: str | None
    updated_at: datetime


class CaldavUserConfigSave(BaseModel):
    enabled: bool = False
    principal_url: str = Field(min_length=1)
    calendar_url: str | None = None
    username: str = Field(min_length=1, max_length=255)
    password: str | None = None
    calendar_display_name: str = ""
    verify_ssl: bool = True


class ResyncResult(BaseModel):
    synced: int
    failed: int
    total: int
