from pydantic import BaseModel, validator
from typing import Optional, List
from datetime import datetime

class RecurrencePatternBase(BaseModel):
    type: str
    interval: int = 1
    days_of_week: Optional[List[int]] = None
    end_date: Optional[datetime] = None
    max_occurrences: Optional[int] = None

    @validator('type')
    def type_must_be_valid(cls, v):
        if v not in ['daily', 'weekly', 'monthly', 'yearly']:
            raise ValueError("type must be one of 'daily', 'weekly', 'monthly', 'yearly'")
        return v

    @validator('days_of_week')
    def days_of_week_must_be_valid(cls, v):
        if v:
            for day in v:
                if not 0 <= day <= 6:
                    raise ValueError("days_of_week must be between 0 and 6")
        return v

class RecurrencePatternCreate(RecurrencePatternBase):
    pass

class RecurrencePatternPublic(RecurrencePatternBase):
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        orm_mode = True 