"""Waitlist schemas for request and response."""

from datetime import date, datetime
from typing import Optional

from pydantic import BaseModel, EmailStr, Field


class WaitlistCreate(BaseModel):
    """Schema for creating a waitlist entry."""
    fullName: str = Field(..., min_length=1, max_length=200)
    gender: str = Field(..., min_length=1, max_length=20)
    email: EmailStr
    phone: str = Field(..., min_length=10, max_length=20)
    whatsappPhone: Optional[str] = Field(None, max_length=20)
    dob: date
    age: Optional[str] = Field(None, max_length=10)
    state: str = Field(..., min_length=1, max_length=100)
    lga: str = Field(..., min_length=1, max_length=100)
    qualification: str = Field(..., min_length=1, max_length=50)
    # Source tracking (optional)
    source: Optional[str] = Field(None, max_length=20)  # 'personal', 'corporate', 'edu'
    sourceName: Optional[str] = Field(None, max_length=255)
    sourceId: Optional[str] = Field(None)  # UUID string
    # Optional slug identifier for partner; backend will attempt
    # to resolve this to a concrete partner record when sourceId
    # is missing or when additional enrichment is needed.
    sourceSlug: Optional[str] = Field(None, max_length=255)


class WaitlistResponse(BaseModel):
    """Schema for waitlist response."""
    id: str
    fullName: str
    gender: str
    email: str
    phone: str
    whatsappPhone: Optional[str] = None
    dob: date
    age: Optional[str] = None
    state: str
    lga: str
    qualification: str
    # Source tracking
    source: Optional[str] = None
    sourceName: Optional[str] = None
    sourceId: Optional[str] = None
    # Engagement tracking
    invitationSent: bool = False
    invitationSentAt: Optional[datetime] = None
    followupCount: int = 0
    lastFollowupAt: Optional[datetime] = None
    hasApplied: bool = False
    applicationId: Optional[str] = None
    status: str = "waiting"
    # Timestamps
    createdAt: datetime
    updatedAt: datetime

    class Config:
        from_attributes = True
        populate_by_name = True


class WaitlistPrefillResponse(BaseModel):
    """Public schema for application form prefill only (no auth required)."""
    id: str
    fullName: str
    gender: str
    email: str
    phone: str
    whatsappPhone: Optional[str] = None
    dob: date
    age: Optional[str] = None
    state: str
    lga: str
    qualification: str


class SendEmailRequest(BaseModel):
    """Schema for send email request."""
    isFollowup: bool = False


class UpdateStatusRequest(BaseModel):
    """Schema for update status request."""
    status: str = Field(..., pattern="^(waiting|invited|engaged|converted)$")
