from datetime import datetime

from pydantic import BaseModel, Field


class LearnerCreate(BaseModel):
    phone: str = Field(min_length=6, max_length=32)
    current_name: str = Field(min_length=1, max_length=64)
    student_no: str | None = Field(default=None, max_length=64)
    remark: str | None = None


class LearnerUpdate(BaseModel):
    phone: str = Field(min_length=6, max_length=32)
    current_name: str = Field(min_length=1, max_length=64)
    student_no: str | None = Field(default=None, max_length=64)
    status: str = Field(default="active", pattern="^(active|disabled|deleted)$")
    remark: str | None = None


class LearnerOut(BaseModel):
    id: int
    phone: str
    current_name: str
    student_no: str | None
    status: str
    remark: str | None
    certificate_count: int = 0
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}


class LearnerImportError(BaseModel):
    row_no: int
    message: str


class LearnerImportResult(BaseModel):
    total_rows: int
    created_rows: int
    updated_rows: int
    unchanged_rows: int
    failed_rows: int
    errors: list[LearnerImportError]
