#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
模块名称：security_erp_task.py
模块描述：安全测试 ERP 任务创建 Pydantic Schema

作者：czj
创建日期：2026-08-17
最后修改：2026-08-17
"""

from typing import Any, Dict, List, Optional

from pydantic import BaseModel, Field


class TaskStaffInfo(BaseModel):
    """ERP 人员信息"""
    id: int = Field(..., description="人员ID")
    name: str = Field("", description="人员姓名")


class TaskTypeInfo(BaseModel):
    """ERP 任务类型"""
    id: int = Field(..., description="类型ID")
    name: str = Field("", description="类型名称")


class TaskStatusInfo(BaseModel):
    """ERP 任务状态"""
    id: int = Field(..., description="状态ID")
    name: str = Field("", description="状态名称")


class RequirementInfo(BaseModel):
    """ERP 需求信息"""
    id: int = Field(..., description="需求ID")
    name: str = Field("", description="需求名称")


class TaskDefaultConfig(BaseModel):
    """任务默认配置"""
    type_id: int = Field(3, description="任务类型ID")
    status_id: int = Field(1, description="任务状态ID")
    level: int = Field(4, description="紧急程度（1-5）")
    excepthour: int = Field(21, description="期望工时（小时）")
    user_id: int = Field(101, description="责任人ID")
    createuser_id: int = Field(441, description="创建人ID")
    deadline_days: int = Field(7, description="截止天数")


class ReportSummary(BaseModel):
    """报告摘要"""
    target: str = Field("", description="测试目标URL")
    server_ip: str = Field("", description="服务器IP")
    start_time: str = Field("", description="测试开始时间")
    end_time: str = Field("", description="测试结束时间")
    total: int = Field(0, description="测试用例总数")
    high: int = Field(0, description="高危漏洞数")
    medium: int = Field(0, description="中危漏洞数")
    low: int = Field(0, description="低危漏洞数")
    info: int = Field(0, description="信息类数")
    safe: int = Field(0, description="安全项数")


class TaskPreviewResponse(BaseModel):
    """任务创建预览响应"""
    summary: ReportSummary = Field(..., description="报告摘要")
    task_name: str = Field("", description="自动生成的任务名称")
    calculated_level: int = Field(4, description="自动计算的紧急程度")
    task_types: List[TaskTypeInfo] = Field(default_factory=list, description="任务类型列表")
    task_statuses: List[TaskStatusInfo] = Field(default_factory=list, description="任务状态列表")
    staff_list: List[TaskStaffInfo] = Field(default_factory=list, description="人员列表")
    requirement: Optional[RequirementInfo] = Field(None, description="关联需求")
    default_config: TaskDefaultConfig = Field(default_factory=TaskDefaultConfig, description="默认配置")


class CreateTaskRequest(BaseModel):
    """创建 ERP 任务请求"""
    type_id: int = Field(3, description="任务类型ID")
    status_id: int = Field(1, description="任务状态ID")
    level: int = Field(4, description="紧急程度（1-5）")
    excepthour: int = Field(21, description="期望工时（小时）")
    user_id: int = Field(101, description="责任人ID")
    createuser_id: int = Field(441, description="创建人ID")
    deadline_days: int = Field(7, description="截止天数（从当前时间+N天）")
    develop_id: Optional[int] = Field(None, description="关联需求ID（可选）")
    task_name: Optional[str] = Field(None, description="任务名称（可选，自动生成）")


class CreateTaskResponse(BaseModel):
    """创建 ERP 任务响应"""
    success: bool = Field(..., description="是否成功")
    task_id: Optional[int] = Field(None, description="ERP任务ID")
    task_name: str = Field("", description="任务名称")
    message: str = Field("", description="提示信息")