from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime
from models.event import ParticipationStatus

class EventBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=200)
    description: Optional[str] = None
    location: Optional[str] = None
    latitude: Optional[float] = None
    longitude: Optional[float] = None
    date: datetime
    end_date: Optional[datetime] = None

class EventCreate(EventBase):
    cover_image: Optional[str] = None

class EventUpdate(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=200)
    description: Optional[str] = None
    location: Optional[str] = None
    latitude: Optional[float] = None
    longitude: Optional[float] = None
    date: Optional[datetime] = None
    end_date: Optional[datetime] = None
    cover_image: Optional[str] = None

class ParticipationResponse(BaseModel):
    user_id: int
    username: str
    full_name: str
    avatar_url: Optional[str]
    status: ParticipationStatus
    response_date: datetime
    
    class Config:
        from_attributes = True

class EventResponse(EventBase):
    id: int
    creator_id: int
    creator_name: str
    creator_avatar: Optional[str] = None
    cover_image: Optional[str]
    created_at: datetime
    participations: List[ParticipationResponse] = []
    present_count: int = 0
    absent_count: int = 0
    maybe_count: int = 0
    pending_count: int = 0
    
    class Config:
        from_attributes = True

class ParticipationUpdate(BaseModel):
    status: ParticipationStatus
