using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using FreeSql.DataAnnotations;
using ZhonTai.Admin.Core.Entities;
using NPP.SmartSchedue.Api.Contracts.Core.Consts;
using NPP.SmartSchedue.Api.Contracts.Core.Enums;
using NPP.SmartSchedue.Api.Contracts.Domain.Personnel;
using NPP.SmartSchedue.Api.Contracts.Domain.Time;
using NPP.SmartSchedue.Api.Contracts.Domain.Equipment;

namespace NPP.SmartSchedue.Api.Contracts.Domain.Work;

/// <summary>
/// 工作任务实体
/// </summary>
[Table(Name = DbConsts.TableNamePrefix + "work_order")]
public partial class WorkOrderEntity : EntityTenant
{
    #region 基础信息
    
    /// <summary>
    /// 项目号
    /// </summary>
    [Column(StringLength = 50)]
    [Required(ErrorMessage = "项目号不能为空")]
    public string ProjectNumber { get; set; }

    /// <summary>
    /// 项目类别
    /// </summary>
    [Column(StringLength = 50)]
    [Required(ErrorMessage = "项目类别不能为空")]
    public string ProjectCategory { get; set; }

    /// <summary>
    /// 班次ID
    /// </summary>
    public long? ShiftId { get; set; }

    /// <summary>
    /// 班次代码
    /// </summary>
    [Column(StringLength = 20)]
    public string ShiftCode { get; set; }

    /// <summary>
    /// 班次名称
    /// </summary>
    [Column(StringLength = 100)]
    public string ShiftName { get; set; }

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

    /// <summary>
    /// 工序代码
    /// </summary>
    [Column(StringLength = 20)]
    public string ProcessCode { get; set; }

    /// <summary>
    /// 工序名称
    /// </summary>
    [Column(StringLength = 100)]
    public string ProcessName { get; set; }

    /// <summary>
    /// 工序分类
    /// </summary>
    public string ProcessCategory { get; set; }

    #endregion

    #region 任务信息

    /// <summary>
    /// 任务代码（项目号_班次code_工序code）
    /// </summary>
    [Column(StringLength = 100)]
    public string WorkOrderCode { get; set; }

    /// <summary>
    /// 批号
    /// </summary>
    [Column(StringLength = 50)]
    public string BatchNumber { get; set; }

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

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

    /// <summary>
    /// 优先级（1-10，数字越大优先级越高）
    /// </summary>
    public int Priority { get; set; } = 5;

    /// <summary>
    /// 预计工时（小时）
    /// </summary>
    [Column(Precision = 10, Scale = 2)]
    public decimal? EstimatedHours { get; set; }

    /// <summary>
    /// 紧急程度（1-10，数字越大越紧急）
    /// </summary>
    public int Urgency { get; set; } = 5;

    /// <summary>
    /// 任务复杂度（别名，使用Priority表示）
    /// </summary>
    [Column(MapType = typeof(int), IsIgnore = true)]
    public int Complexity 
    { 
        get => Priority; 
        set => Priority = value; 
    }

    /// <summary>
    /// 权重系数（用于排序和优先级计算）
    /// </summary>
    [Column(Precision = 10, Scale = 4)]
    public double WeightFactor { get; set; } = 1.0;

    #endregion

    #region 人员和设备

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

    /// <summary>
    /// 任务实施人员姓名
    /// </summary>
    [Column(StringLength = 100)]
    public string AssignedPersonnelName { get; set; }

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

    /// <summary>
    /// 任务设备名称
    /// </summary>
    [Column(StringLength = 200)]
    public string AssignedEquipmentName { get; set; }

    /// <summary>
    /// 需要岗位负责人
    /// </summary>
    public bool NeedPostHead { get; set; } = false;

    #endregion

    #region 时间信息

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

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

    /// <summary>
    /// 实际完成工时（小时）
    /// </summary>
    [Column(Precision = 10, Scale = 2)]
    public decimal? ActualWorkHours { get; set; }

    /// <summary>
    /// 实际完成工时（别名，与 ActualWorkHours 相同）
    /// </summary>
    [Column(MapType = typeof(decimal?), IsIgnore = true)]
    public decimal? ActualCompletedHours 
    { 
        get => ActualWorkHours; 
        set => ActualWorkHours = value; 
    }

    /// <summary>
    /// 任务分配时间
    /// </summary>
    public DateTime? AssignedTime { get; set; }

    /// <summary>
    /// 最后修改时间
    /// </summary>
    public DateTime? LastModifiedTime { get; set; }

    /// <summary>
    /// 备注信息
    /// </summary>
    [Column(StringLength = 1000)]
    public string Remarks { get; set; } = "";

    /// <summary>
    /// 计划开始时间
    /// </summary>
    public DateTime PlannedStartTime { get; set; }

    /// <summary>
    /// 计划结束时间
    /// </summary>
    public DateTime PlannedEndTime { get; set; }

    /// <summary>
    /// 任务代码/编号
    /// </summary>
    [Column(StringLength = 100)]
    public string Code { get; set; } = "";


    /// <summary>
    /// 紧急程度级别（使用Urgency的别名）
    /// </summary>
    [Column(MapType = typeof(int), IsIgnore = true)]
    public int UrgencyLevel 
    { 
        get => Urgency; 
        set => Urgency = value; 
    }

    /// <summary>
    /// 复杂度级别（使用Priority的别名）
    /// </summary>
    [Column(MapType = typeof(int), IsIgnore = true)]
    public int ComplexityLevel 
    { 
        get => Priority; 
        set => Priority = value; 
    }

    /// <summary>
    /// 整合记录ID
    /// </summary>
    public long? IntegrationRecordId { get; set; }

    #endregion

    #region 导航属性

    /// <summary>
    /// 工序实体
    /// </summary>
    [Navigate("ProcessId")]
    public ProcessEntity? ProcessEntity { get; set; }

    /// <summary>
    /// 班次实体
    /// </summary>
    [Navigate("ShiftId")]
    public ShiftEntity? ShiftEntity { get; set; }

    /// <summary>
    /// FL人员关联列表
    /// </summary>
    [Navigate("WorkOrderId")]
    public List<WorkOrderFLPersonnelEntity> WorkOrderFLPersonnels { get; set; } = new List<WorkOrderFLPersonnelEntity>();


    #endregion
} 