from pydantic import BaseModel, Field


# ── M1: Linear Regression — avg_final ─────────────────────────────────────────

class AvgFinalInput(BaseModel):
    age: int = Field(..., ge=11, le=25, description="Edad del estudiante")
    gender_encoded: int = Field(..., ge=0, le=1, description="Género: 0=F, 1=M")
    course_encoded: int = Field(
        ..., ge=0, le=6,
        description="Curso: 0=Primary6, 1=Sec1, 2=Sec2, 3=Sec3, 4=Sec4, 5=Sec5, 6=Sec6",
    )
    attendance_absences_total: int = Field(..., ge=0, description="Total de ausencias")
    support_level_num: int = Field(..., ge=0, le=2, description="Apoyo: 0=Low, 1=Medium, 2=High")
    total_subjects: int = Field(..., ge=1, le=20, description="Nº de asignaturas cursadas")
    term1_avg: float = Field(..., ge=0.0, le=100.0, description="Promedio de notas del trimestre 1")


class AvgFinalOutput(BaseModel):
    predicted_avg_final: float
    model: str = "M1 — Linear Regression (avg_final)"


# ── M4: Linear Regression — Mathematics_final ─────────────────────────────────

class MathFinalInput(BaseModel):
    Mathematics_term1: float = Field(..., ge=0.0, le=100.0)
    Mathematics_term2: float = Field(..., ge=0.0, le=100.0)
    Mathematics_term3: float = Field(..., ge=0.0, le=100.0)
    attendance_absences_total: int = Field(..., ge=0)


class MathFinalOutput(BaseModel):
    predicted_math_final: float
    model: str = "M4 — Linear Regression (Mathematics_final)"


# ── M2: Logistic Regression — grade_tendency ──────────────────────────────────

class GradeTendencyInput(BaseModel):
    term1_avg: float = Field(..., ge=0.0, le=100.0, description="Promedio trimestre 1")
    term2_avg: float = Field(..., ge=0.0, le=100.0, description="Promedio trimestre 2")
    term3_avg: float = Field(..., ge=0.0, le=100.0, description="Promedio trimestre 3")
    attendance_absences_total: int = Field(..., ge=0)
    support_level_num: int = Field(..., ge=0, le=2, description="0=Low, 1=Medium, 2=High")
    age: int = Field(..., ge=11, le=25)
    gender_encoded: int = Field(..., ge=0, le=1, description="0=F, 1=M")


class GradeTendencyOutput(BaseModel):
    predicted_class: int
    label: str
    probability_downtrend: float
    probability_uptrend: float
    model: str = "M2 — Logistic Regression (grade_tendency)"


# ── M3: Logistic Regression — Mathematics pass/fail ───────────────────────────

class MathPassInput(BaseModel):
    Mathematics_term1: float = Field(..., ge=0.0, le=100.0)
    Mathematics_term2: float = Field(..., ge=0.0, le=100.0)
    Mathematics_term3: float = Field(..., ge=0.0, le=100.0)
    attendance_absences_total: int = Field(..., ge=0)
    support_level_num: int = Field(..., ge=0, le=2, description="0=Low, 1=Medium, 2=High")


class MathPassOutput(BaseModel):
    predicted_class: int
    label: str
    probability_fail: float
    probability_pass: float
    model: str = "M3 — Logistic Regression (Mathematics pass/fail)"


# ── M5: Multinomial Logistic — support_level ──────────────────────────────────

class SupportLevelInput(BaseModel):
    term1_avg: float = Field(..., ge=0.0, le=100.0)
    attendance_absences_total: int = Field(..., ge=0)
    failed_subjects: int = Field(..., ge=0)
    grade_tendency_encoded: int = Field(..., ge=0, le=1, description="0=Downtrend/Stable, 1=Uptrend")
    age: int = Field(..., ge=11, le=25)
    gender_encoded: int = Field(..., ge=0, le=1, description="0=F, 1=M")


class SupportLevelOutput(BaseModel):
    predicted_class: int
    label: str
    probability_low: float
    probability_medium: float
    probability_high: float
    model: str = "M5 — Multinomial Logistic Regression (support_level)"
