from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field

class CookieCategoryPreferences(BaseModel):
    necessary: bool = Field(default=True, description='Strictly necessary cookies (always enabled as they are required for core functionality).')
    analytics: bool = Field(default=False, description='Allow anonymous analytics and performance cookies.')
    marketing: bool = Field(default=False, description='Allow marketing and advertising cookies.')
    preferences: bool = Field(default=False, description='Allow preference cookies (e.g. language, layout settings).')

class CookieConsent(BaseModel):
    version: int = Field(default=1, description='Consent schema version for future migrations.')
    updated_at: datetime = Field(default_factory=datetime.utcnow, description='Last time consent was updated.')
    has_decided: bool = Field(default=False, description='Whether the user has actively made a consent choice.')
    categories: CookieCategoryPreferences = Field(default_factory=CookieCategoryPreferences, description='Granular per-category consent.')

class CookieConsentResponse(BaseModel):
    status: str = Field(default='success')
    data: CookieConsent

class UpdateCookieConsentRequest(BaseModel):
    analytics: Optional[bool] = None
    marketing: Optional[bool] = None
    preferences: Optional[bool] = None