"""
Pydantic Schemas — request/response validation
Placed in schemas/schemas.py so both ..schemas.schemas and ..models.schemas imports work.
"""
from pydantic import BaseModel, EmailStr, Field
from typing import Optional
from datetime import datetime


# ── Auth ───────────────────────────────────────────────────
class UserRegister(BaseModel):
    full_name: str = Field(..., min_length=2, max_length=100)
    email: EmailStr
    password: str = Field(..., min_length=6)
    role: str = Field(default="client", pattern="^(client|lawyer)$")
    city: Optional[str] = None


class UserLogin(BaseModel):
    email: EmailStr
    password: str


class Token(BaseModel):
    access_token: str
    token_type: str = "bearer"
    role: str
    full_name: str


class UserOut(BaseModel):
    id: int
    full_name: str
    email: str
    role: str
    city: Optional[str]
    created_at: datetime

    class Config:
        from_attributes = True


# ── Case ───────────────────────────────────────────────────
class CaseCreate(BaseModel):
    description: str = Field(..., min_length=20, max_length=5000)


class CaseOut(BaseModel):
    id: int
    description: str
    category: Optional[str]
    summary: Optional[str]
    legal_guidance: Optional[str]
    status: str
    created_at: datetime

    class Config:
        from_attributes = True


# ── AI ─────────────────────────────────────────────────────
class AIAnalysisRequest(BaseModel):
    description: str = Field(..., min_length=20)


class AIAnalysisResponse(BaseModel):
    category: str
    summary: str
    legal_guidance: str
    confidence: str


# ── Lawyer ─────────────────────────────────────────────────
class LawyerOut(BaseModel):
    id: int
    name: str
    gender: str
    city: str
    specialization: str
    experience_years: int
    consultation_fee_pkr: float
    rating: float
    total_cases_handled: int
    success_rate_percentage: float
    law_firm_name: str
    contact_email: str

    class Config:
        from_attributes = True


class LawyerRecommendation(BaseModel):
    lawyer: LawyerOut
    match_score: float
    reason: str


# ── Appointment ────────────────────────────────────────────
class AppointmentCreate(BaseModel):
    lawyer_id: int
    case_id: Optional[int] = None
    appointment_date: str
    appointment_time: str
    notes: Optional[str] = None


class AppointmentOut(BaseModel):
    id: int
    lawyer_id: int
    case_id: Optional[int]
    appointment_date: str
    appointment_time: str
    status: str
    notes: Optional[str]
    created_at: datetime

    class Config:
        from_attributes = True
