""" Contact models — People and organizations you call. """ from datetime import datetime from typing import Optional from pydantic import BaseModel, Field class PhoneNumber(BaseModel): """A phone number associated with a contact.""" number: str # E.164 format label: str = "main" # main, mobile, work, home, fax, etc. primary: bool = False class ContactBase(BaseModel): """Shared contact fields.""" name: str phone_numbers: list[PhoneNumber] category: Optional[str] = None # personal / business / service routing_preference: Optional[str] = None # how to handle their calls notes: Optional[str] = None class Contact(ContactBase): """Full contact model.""" id: str call_count: int = 0 last_call: Optional[datetime] = None created_at: Optional[datetime] = None updated_at: Optional[datetime] = None @property def primary_number(self) -> Optional[str]: """Get the primary phone number.""" for pn in self.phone_numbers: if pn.primary: return pn.number return self.phone_numbers[0].number if self.phone_numbers else None class ContactCreate(ContactBase): """Request model for creating a contact.""" pass class ContactUpdate(BaseModel): """Request model for updating a contact.""" name: Optional[str] = None phone_numbers: Optional[list[PhoneNumber]] = None category: Optional[str] = None routing_preference: Optional[str] = None notes: Optional[str] = None