"""Admin Fine-Tune Pool Schemas."""

from datetime import datetime

from pydantic import BaseModel, Field


class PoolAddRequest(BaseModel):
    """Request to add a document to the fine-tune pool."""

    document_id: str = Field(..., description="Document UUID to add")
    reason: str = Field(
        default="user_reported_failure",
        description="Reason: user_reported_failure, manual_addition",
    )


class PoolEntryItem(BaseModel):
    """Fine-tune pool entry."""

    entry_id: str = Field(..., description="Entry UUID")
    document_id: str = Field(..., description="Document UUID")
    added_by: str | None = Field(None, description="Who added this entry")
    reason: str | None = Field(None, description="Reason for adding")
    is_verified: bool = Field(..., description="Whether entry has been verified")
    verified_at: datetime | None = Field(None, description="Verification timestamp")
    verified_by: str | None = Field(None, description="Who verified")
    created_at: datetime = Field(..., description="Creation timestamp")


class PoolListResponse(BaseModel):
    """Paginated pool entry list."""

    total: int = Field(..., ge=0, description="Total entries")
    limit: int = Field(..., ge=1, description="Page size")
    offset: int = Field(..., ge=0, description="Current offset")
    entries: list[PoolEntryItem] = Field(default_factory=list, description="Pool entries")


class PoolStatsResponse(BaseModel):
    """Pool statistics."""

    total_entries: int = Field(..., ge=0, description="Total pool entries")
    verified_entries: int = Field(..., ge=0, description="Verified entries")
    unverified_entries: int = Field(..., ge=0, description="Unverified entries")
    is_ready: bool = Field(..., description="Whether pool has >= 50 verified entries for fine-tuning")
    min_required: int = Field(default=50, description="Minimum verified entries required")


class PoolEntryResponse(BaseModel):
    """Response for pool entry operation."""

    entry_id: str = Field(..., description="Entry UUID")
    message: str = Field(..., description="Status message")


class GatingResultItem(BaseModel):
    """Gating validation result."""

    result_id: str = Field(..., description="Result UUID")
    model_version_id: str = Field(..., description="Model version UUID")
    gate1_status: str = Field(..., description="Gate 1 status")
    gate1_original_mAP: float | None = Field(None, description="Original model mAP")
    gate1_new_mAP: float | None = Field(None, description="New model mAP")
    gate1_mAP_drop: float | None = Field(None, description="mAP drop percentage")
    gate2_status: str = Field(..., description="Gate 2 status")
    gate2_detection_rate: float | None = Field(None, description="Detection rate on new samples")
    gate2_total_samples: int | None = Field(None, description="Total new samples tested")
    gate2_detected_samples: int | None = Field(None, description="Samples correctly detected")
    overall_status: str = Field(..., description="Overall gating status")
    reviewer_notes: str | None = Field(None, description="Reviewer notes")
    created_at: datetime = Field(..., description="Creation timestamp")
