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

namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Output;

/// <summary>
/// 整合记录详细信息
/// 包含完整的任务分配详情、人员信息、设备信息等
/// </summary>
public class IntegrationRecordDetail
{
    /// <summary>
    /// 记录ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 整合批次编码
    /// </summary>
    public string IntegrationBatchCode { get; set; } = string.Empty;

    /// <summary>
    /// 整合时间
    /// </summary>
    public DateTime IntegrationTime { get; set; }

    /// <summary>
    /// 操作员用户ID
    /// </summary>
    public long OperatorUserId { get; set; }

    /// <summary>
    /// 操作员用户名
    /// </summary>
    public string OperatorUserName { get; set; } = string.Empty;

    /// <summary>
    /// 操作员真实姓名
    /// </summary>
    public string OperatorRealName { get; set; } = string.Empty;

    /// <summary>
    /// 策略配置详情
    /// </summary>
    public IntegrationStrategyConfig StrategyConfig { get; set; } = new();

    /// <summary>
    /// 人员分配结果详情
    /// </summary>
    public PersonnelAllocationResult? PersonnelAllocationResult { get; set; }

    /// <summary>
    /// 设备分配结果详情
    /// </summary>
    public EquipmentAllocationResult? EquipmentAllocationResult { get; set; }

    /// <summary>
    /// 任务详细信息列表
    /// </summary>
    public List<TaskDetailForRecord> TaskDetails { get; set; } = new();

    /// <summary>
    /// 成功任务数
    /// </summary>
    public int SuccessTaskCount { get; set; }

    /// <summary>
    /// 失败任务数
    /// </summary>
    public int FailedTaskCount { get; set; }

    /// <summary>
    /// 执行耗时（毫秒）
    /// </summary>
    public long ElapsedMilliseconds { get; set; }

    /// <summary>
    /// 公平性评分
    /// </summary>
    public int FairnessScore { get; set; }

    /// <summary>
    /// 设备利用率
    /// </summary>
    public decimal UtilizationRate { get; set; }

    /// <summary>
    /// 备注信息
    /// </summary>
    public string Remarks { get; set; } = string.Empty;

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedTime { get; set; }
}

/// <summary>
/// 整合策略配置
/// 用于展示策略详细配置信息
/// </summary>
public class IntegrationStrategyConfig
{
    /// <summary>
    /// 人员分配策略
    /// </summary>
    public string PersonnelStrategy { get; set; } = string.Empty;

    /// <summary>
    /// 设备分配策略
    /// </summary>
    public string EquipmentStrategy { get; set; } = string.Empty;

    /// <summary>
    /// 是否强制执行班次规则
    /// </summary>
    public bool EnforceShiftRules { get; set; }

    /// <summary>
    /// 是否优先处理高优先级任务
    /// </summary>
    public bool PrioritizeHighPriorityTasks { get; set; }

    /// <summary>
    /// 是否考虑资质匹配度
    /// </summary>
    public bool ConsiderQualificationMatch { get; set; }

    /// <summary>
    /// 是否启用负载均衡
    /// </summary>
    public bool EnableLoadBalancing { get; set; }

    /// <summary>
    /// 最大连续工作天数
    /// </summary>
    public int MaxContinuousWorkDays { get; set; }

    /// <summary>
    /// 目标设备利用率
    /// </summary>
    public decimal TargetEquipmentUtilization { get; set; }
}

/// <summary>
/// 记录中的任务详细信息
/// 用于展示任务在整合记录中的完整信息
/// </summary>
public class TaskDetailForRecord
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long TaskId { get; set; }

    /// <summary>
    /// 任务代码
    /// </summary>
    public string TaskCode { get; set; } = string.Empty;

    /// <summary>
    /// 项目号
    /// </summary>
    public string ProjectNumber { get; set; } = string.Empty;

    /// <summary>
    /// 项目类别
    /// </summary>
    public string ProjectCategory { get; set; } = string.Empty;

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

    /// <summary>
    /// 班次名称
    /// </summary>
    public string ShiftName { get; set; } = string.Empty;

    /// <summary>
    /// 工序ID
    /// </summary>
    public long ProcessId { get; set; }

    /// <summary>
    /// 工序名称
    /// </summary>
    public string ProcessName { get; set; } = string.Empty;

    /// <summary>
    /// 工作日期
    /// </summary>
    public DateTime WorkOrderDate { get; set; }

    /// <summary>
    /// 优先级
    /// </summary>
    public int Priority { get; set; }

    /// <summary>
    /// 紧急程度
    /// </summary>
    public int Urgency { get; set; }

    /// <summary>
    /// 复杂度
    /// </summary>
    public int Complexity { get; set; }

    /// <summary>
    /// 预计工时
    /// </summary>
    public decimal? EstimatedHours { get; set; }

    /// <summary>
    /// 任务状态
    /// </summary>
    public int Status { get; set; }

    /// <summary>
    /// 分配的人员ID
    /// </summary>
    public long? AssignedPersonnelId { get; set; }

    /// <summary>
    /// 分配的人员姓名
    /// </summary>
    public string AssignedPersonnelName { get; set; } = string.Empty;

    /// <summary>
    /// 分配的设备ID
    /// </summary>
    public long? AssignedEquipmentId { get; set; }

    /// <summary>
    /// 分配的设备名称
    /// </summary>
    public string AssignedEquipmentName { get; set; } = string.Empty;

    /// <summary>
    /// 权重
    /// </summary>
    public double WeightFactor { get; set; }
    
    /// <summary>
    /// 备注
    /// </summary>
    public string Remarks { get; set; } = string.Empty;
}