# -*- coding: utf-8 -*-
"""P18 任务引擎运营看板 — Pydantic v2 Schema

包含：转移日志、待审核任务、候选助教、参数管理等数据模型。
"""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field


# ---- 转移日志 ----

class TransferLogItem(BaseModel):
    id: int
    site_id: int
    site_name: str = ""
    member_id: int
    member_name: str = ""
    from_assistant_id: int
    from_assistant_name: str = ""
    to_assistant_id: int
    to_assistant_name: str = ""
    transfer_reason: str | None = None
    transfer_score: float | None = None
    guard_checks: dict | None = None
    created_at: datetime


class TransferLogPage(BaseModel):
    items: list[TransferLogItem]
    total: int


# ---- 待审核任务 ----

class PendingReviewItem(BaseModel):
    id: int
    site_id: int
    site_name: str = ""
    member_id: int
    member_name: str = ""
    assistant_id: int
    assistant_name: str = ""
    task_type: str
    task_type_label: str = ""
    transfer_count: int = 0
    priority_score: float | None = None
    created_at: datetime


class PendingReviewPage(BaseModel):
    items: list[PendingReviewItem]
    total: int


class CandidateAssistant(BaseModel):
    assistant_id: int
    assistant_name: str = ""
    rs_display: float = 0
    ms_display: float = 0
    ml_display: float = 0
    transfer_score: float = 0
    source: str = "pool"


class CandidateListResponse(BaseModel):
    candidates: list[CandidateAssistant]


class ReassignRequest(BaseModel):
    to_assistant_id: int


class ReassignResponse(BaseModel):
    success: bool
    new_task_id: int | None = None


class CloseRequest(BaseModel):
    reason: str = Field(..., min_length=1, max_length=500)


class CloseResponse(BaseModel):
    success: bool


# ---- 参数管理 ----

class ConfigParam(BaseModel):
    id: int
    site_id: int | None = None
    site_name: str | None = None
    param_key: str
    param_value: float
    description: str | None = None
    updated_at: datetime


class ConfigParamList(BaseModel):
    params: list[ConfigParam]


class ConfigParamUpdate(BaseModel):
    param_value: float


class ConfigParamCreate(BaseModel):
    site_id: int
    param_key: str = Field(..., max_length=64)
    param_value: float


class ConfigParamResponse(BaseModel):
    success: bool
    id: int | None = None
