from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field


class EmergencyContactBase(BaseModel):
    name: str = Field(..., min_length=1, max_length=100)
    phone_number: str = Field(..., min_length=5, max_length=20)
    relationship: Optional[str] = Field(None, max_length=50)
    notes: Optional[str] = Field(None, max_length=500)


class EmergencyContactCreate(EmergencyContactBase):
    pass


class EmergencyContactUpdate(BaseModel):
    name: Optional[str] = Field(None, min_length=1, max_length=100)
    phone_number: Optional[str] = Field(None, min_length=5, max_length=20)
    relationship: Optional[str] = Field(None, max_length=50)
    notes: Optional[str] = Field(None, max_length=500)


class EmergencyContactResponse(EmergencyContactBase):
    id: int
    uuid: UUID
    user_id: int

    model_config = {
        "from_attributes": True,
        "populate_by_name": True,
        "json_schema_extra": {
            "examples": [
                {
                    "name": "John Doe",
                    "phone_number": "+1234567890",
                    "relationship": "Father",
                    "notes": "Call in case of emergency",
                    "id": 1,
                    "uuid": "550e8400-e29b-41d4-a716-446655440000",
                    "user_id": 1,
                }
            ]
        }
    }