using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using NPP.SmartSchedue.Api.Contracts.Core.Enums;

namespace NPP.SmartSchedue.Api.Contracts.Services.Work.Input;

/// <summary>
/// 添加工作任务
/// </summary>
public class WorkOrderAddInput
{
    #region 基础信息
    
    /// <summary>
    /// 项目号
    /// </summary>
    [Required(ErrorMessage = "项目号不能为空")]
    [MaxLength(50, ErrorMessage = "项目号长度不能超过50个字符")]
    public string ProjectNumber { get; set; }

    /// <summary>
    /// 项目类别
    /// </summary>
    [Required(ErrorMessage = "项目类别不能为空")]
    [MaxLength(50, ErrorMessage = "项目类别长度不能超过50个字符")]
    public string ProjectCategory { get; set; }

    /// <summary>
    /// 班次ID
    /// </summary>
    [Required(ErrorMessage = "班次不能为空")]
    public long ShiftId { get; set; }

    /// <summary>
    /// 班次代码
    /// </summary>
    [MaxLength(20, ErrorMessage = "班次代码长度不能超过20个字符")]
    public string ShiftCode { get; set; }

    /// <summary>
    /// 班次名称
    /// </summary>
    [MaxLength(100, ErrorMessage = "班次名称长度不能超过100个字符")]
    public string ShiftName { get; set; }

    /// <summary>
    /// 工序ID
    /// </summary>
    [Required(ErrorMessage = "工序不能为空")]
    public long ProcessId { get; set; }

    /// <summary>
    /// 工序代码
    /// </summary>
    [MaxLength(20, ErrorMessage = "工序代码长度不能超过20个字符")]
    public string ProcessCode { get; set; }

    /// <summary>
    /// 工序名称
    /// </summary>
    [MaxLength(100, ErrorMessage = "工序名称长度不能超过100个字符")]
    public string ProcessName { get; set; }

    #endregion
    
    #region 任务信息

    /// <summary>
    /// 批号
    /// </summary>
    [MaxLength(50, ErrorMessage = "批号长度不能超过50个字符")]
    public string BatchNumber { get; set; }

    /// <summary>
    /// 任务日期
    /// </summary>
    [Required(ErrorMessage = "任务日期不能为空")]
    public DateTime WorkOrderDate { get; set; }

    /// <summary>
    /// 任务状态
    /// </summary>
    public WorkOrderStatusEnum Status { get; set; } = WorkOrderStatusEnum.PendingSubmit;

    /// <summary>
    /// 优先级（1-10，数字越大优先级越高）
    /// </summary>
    [Range(1, 10, ErrorMessage = "优先级必须在1-10之间")]
    public int Priority { get; set; } = 5;

    /// <summary>
    /// 预计工时（小时）
    /// </summary>
    [Range(0.1, 24, ErrorMessage = "预计工时必须在0.1-24小时之间")]
    public decimal? EstimatedHours { get; set; } = 8;

    /// <summary>
    /// 紧急程度（1-10，数字越大越紧急）
    /// </summary>
    [Range(1, 10, ErrorMessage = "紧急程度必须在1-10之间")]
    public int Urgency { get; set; } = 5;

    /// <summary>
    /// 任务复杂度（别名，使用Priority表示）
    /// </summary>
    [Range(1, 10, ErrorMessage = "复杂度必须在1-10之间")]
    public int Complexity 
    { 
        get => Priority; 
        set => Priority = value; 
    }

    #endregion
    
    #region 人员和设备

    /// <summary>
    /// FL人员信息列表
    /// </summary>
    public List<FLPersonnelInfo> FLPersonnels { get; set; } = new List<FLPersonnelInfo>();

    /// <summary>
    /// 任务实施人员ID
    /// </summary>
    public long? AssignedPersonnelId { get; set; }
    
    /// <summary>
    /// 任务实施人员
    /// </summary>
    public string? AssignedPersonnelName { get; set; }

    /// <summary>
    /// 任务设备ID
    /// </summary>
    public long? AssignedEquipmentId { get; set; }
    
    /// <summary>
    /// 任务设备
    /// </summary>
    public string? AssignedEquipmentName { get; set; }

    #endregion
    
    #region 时间信息

    /// <summary>
    /// 任务实际开始时间
    /// </summary>
    public DateTime? ActualStartTime { get; set; }

    /// <summary>
    /// 任务实际结束时间
    /// </summary>
    public DateTime? ActualEndTime { get; set; }

    /// <summary>
    /// 实际完成工时（小时）
    /// </summary>
    [Range(0, double.MaxValue, ErrorMessage = "实际完成工时必须大于等于0")]
    public decimal? ActualWorkHours { get; set; }

    #endregion

    #region 任务人员数量

    /// <summary>
    /// 工作所需人员
    /// </summary>
    public int RequiredPersonnel { get; set; } = 1;

    #endregion
}

/// <summary>
/// FL人员信息
/// </summary>
public class FLPersonnelInfo
{
    /// <summary>
    /// FL人员ID
    /// </summary>
    public long FLPersonnelId { get; set; }

    /// <summary>
    /// FL人员姓名
    /// </summary>
    public string FLPersonnelName { get; set; }
}