#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
模块名称：scheduled_task.py
模块描述：UI 自动化定时任务 Pydantic 数据模型

作者：czj
创建日期：2026-08-19
"""

from typing import Optional, List
from pydantic import BaseModel, Field


class ScheduledTaskCreate(BaseModel):
    """定时任务创建请求"""
    name: str = Field(..., description="任务名称", min_length=1, max_length=100)
    module_ids: List[str] = Field(..., description="选中的模块ID列表")
    schedule_type: str = Field("interval", description="周期模式: interval/daily/weekly")
    interval_value: int = Field(0, description="间隔值（interval）")
    interval_unit: str = Field("minutes", description="间隔单位: minutes/hours/days")
    run_time: str = Field("", description="执行时间 HH:MM（daily/weekly）")
    weekdays: List[int] = Field([], description="星期 [0-6]（weekly）")
    auto_report: bool = Field(True, description="执行完成后自动生成报告")
    enabled: bool = Field(True, description="是否启用")
    case_type: str = Field("ui", description="用例类型: ui/security")
    config_id: Optional[str] = Field(None, description="安全测试配置ID（security时必填）")


class ScheduledTaskUpdate(BaseModel):
    """定时任务更新请求（全部可选，只更新传入字段）"""
    name: Optional[str] = Field(None, description="任务名称")
    module_ids: Optional[List[str]] = Field(None, description="选中的模块ID列表")
    schedule_type: Optional[str] = Field(None, description="周期模式")
    interval_value: Optional[int] = Field(None, description="间隔值")
    interval_unit: Optional[str] = Field(None, description="间隔单位")
    run_time: Optional[str] = Field(None, description="执行时间 HH:MM")
    weekdays: Optional[List[int]] = Field(None, description="星期 [0-6]")
    auto_report: Optional[bool] = Field(None, description="自动生成报告")
    enabled: Optional[bool] = Field(None, description="是否启用")
    case_type: Optional[str] = Field(None, description="用例类型: ui/security")
    config_id: Optional[str] = Field(None, description="安全测试配置ID")


class ToggleRequest(BaseModel):
    """启停请求"""
    enabled: bool = Field(..., description="目标启用状态")
