# -*- coding: utf-8 -*-
"""定时任务管理 — Pydantic 响应模型"""

from __future__ import annotations

from typing import Self

from pydantic import BaseModel, model_validator


class TriggerJobItem(BaseModel):
    """单个定时任务信息"""
    id: int
    job_type: str
    job_name: str
    trigger_condition: str
    trigger_config: dict | None = None
    last_run_at: str | None = None
    next_run_at: str | None = None
    status: str
    description: str | None = None
    last_error: str | None = None
    created_at: str | None = None


class RunJobResult(BaseModel):
    """手动执行结果"""
    success: bool
    message: str


class UpdateTriggerConfigRequest(BaseModel):
    """触发器配置编辑请求（部分更新）"""
    cron_expression: str | None = None      # 5 字段 cron 表达式
    interval_seconds: int | None = None     # 间隔秒数，>= 1

    @model_validator(mode='after')
    def at_least_one_field(self) -> Self:
        if self.cron_expression is None and self.interval_seconds is None:
            raise ValueError('至少提供 cron_expression 或 interval_seconds 之一')
        return self
