using System;
using System.Collections.Generic;
using Minio;
using NPP.SmartSchedue.Api.Contracts.Core.Enums;
using NPP.SmartSchedue.Api.Contracts.Services.Work.Input;

namespace NPP.SmartSchedue.Api.Contracts.Services.Integration.Output
{
    /// <summary>
    /// 任务整合列表输出
    /// </summary>
    public class TaskIntegrationListOutput
    {
        /// <summary>
        /// 按项目号分组的任务列表
        /// </summary>
        public List<ProjectTaskGroup> ProjectTaskGroups { get; set; } = new();
        
        /// <summary>
        /// 总任务数量
        /// </summary>
        public int TotalTaskCount { get; set; }
        
        /// <summary>
        /// 总项目数量
        /// </summary>
        public int TotalProjectCount { get; set; }
        
        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }
        
        /// <summary>
        /// 当前页码
        /// </summary>
        public int CurrentPage { get; set; }
    }
    
    /// <summary>
    /// 项目任务分组
    /// </summary>
    public class ProjectTaskGroup
    {
        /// <summary>
        /// 项目号
        /// </summary>
        public string ProjectNumber { get; set; }
        
        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName { get; set; }
        
        /// <summary>
        /// 项目类别
        /// </summary>
        public string ProjectCategory { get; set; }
        
        /// <summary>
        /// 该项目下的任务列表
        /// </summary>
        public List<WorkOrderSummary> Tasks { get; set; } = new();
        
        /// <summary>
        /// 项目任务总数
        /// </summary>
        public int TaskCount { get; set; }
        
        /// <summary>
        /// 项目预计总工时
        /// </summary>
        public decimal EstimatedTotalHours { get; set; }
        
        /// <summary>
        /// 项目最早开始日期
        /// </summary>
        public DateTime EarliestStartDate { get; set; }
        
        /// <summary>
        /// 项目最晚结束日期
        /// </summary>
        public DateTime LatestEndDate { get; set; }
    }
    
    /// <summary>
    /// 工作任务摘要
    /// </summary>
    public class WorkOrderSummary
    {
        public long Id { get; set; }
        public string WorkOrderCode { get; set; }
        public DateTime WorkOrderDate { get; set; }
        public long ShiftId { get; set; }
        public string ShiftName { get; set; }
        public string ShiftCode { get; set; }
        public long ProcessId { get; set; }
        public string ProcessName { get; set; }
        public string ProcessCode { get; set; }
        public decimal? EstimatedHours { get; set; }
        public int Status { get; set; }
        public int Priority { get; set; }
        public int UrgencyLevel { get; set; }
        public int ComplexityLevel { get; set; }
        
        /// <summary>
        /// 是否已分配人员
        /// </summary>
        public bool HasAssignedPersonnel { get; set; }
        
        /// <summary>
        /// 是否已分配设备
        /// </summary>
        public bool HasAssignedEquipment { get; set; }
        
        /// <summary>
        /// 关联的FL人员信息
        /// </summary>
        public List<FLPersonnelInfo> FLPersonnels { get; set; } = new();
    }
    
    
    /// <summary>
    /// 任务整合前自检结果
    /// </summary>
    public class TaskIntegrationPreCheckResult
    {
        /// <summary>
        /// 自检是否通过
        /// </summary>
        public bool IsCheckPassed { get; set; }
        
        /// <summary>
        /// 检查的项目数量
        /// </summary>
        public int CheckedProjectCount { get; set; }
        
        /// <summary>
        /// 检查的任务数量
        /// </summary>
        public int CheckedTaskCount { get; set; }
        
        /// <summary>
        /// 项目资源充足性检查结果
        /// </summary>
        public List<ProjectResourceSufficiencyResult> ProjectResourceResults { get; set; } = new();
        
        /// <summary>
        /// 整体检查摘要
        /// </summary>
        public string CheckSummary { get; set; }
        
        /// <summary>
        /// 检查时间
        /// </summary>
        public DateTime CheckTime { get; set; } = DateTime.Now;
        
        /// <summary>
        /// 警告信息
        /// </summary>
        public List<string> Warnings { get; set; } = new();
        
        /// <summary>
        /// 错误信息
        /// </summary>
        public List<string> Errors { get; set; } = new();
    }
    
    /// <summary>
    /// 项目资源充足性结果
    /// </summary>
    public class ProjectResourceSufficiencyResult
    {
        /// <summary>
        /// 项目号
        /// </summary>
        public string ProjectNumber { get; set; }
        
        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName { get; set; }
        
        /// <summary>
        /// 人员资源充足性
        /// </summary>
        public bool IsPersonnelSufficient { get; set; }
        
        /// <summary>
        /// 设备资源充足性
        /// </summary>
        public bool IsEquipmentSufficient { get; set; }
        
        /// <summary>
        /// 详细的资源分析
        /// </summary>
        public ProjectResourceAnalysis ResourceAnalysis { get; set; }
    }
    
    /// <summary>
    /// 项目资源分析
    /// </summary>
    public class ProjectResourceAnalysis
    {
        /// <summary>
        /// 按日的人员需求分析
        /// </summary>
        public List<DailyResourceDemand> DailyDemands { get; set; } = new();
        
        /// <summary>
        /// 按周的人员需求分析
        /// </summary>
        public List<WeeklyResourceDemand> WeeklyDemands { get; set; } = new();
    }
    
    /// <summary>
    /// 日资源需求
    /// </summary>
    public class DailyResourceDemand
    {
        public DateTime Date { get; set; }
        public int RequiredPersonnelCount { get; set; }
        public int AvailablePersonnelCount { get; set; }
        public int RequiredEquipmentCount { get; set; }
        public int AvailableEquipmentCount { get; set; }
        public decimal EstimatedWorkHours { get; set; }
        public bool IsSufficient => AvailablePersonnelCount >= RequiredPersonnelCount && 
                                   AvailableEquipmentCount >= RequiredEquipmentCount;
    }
    
    /// <summary>
    /// 周资源需求
    /// </summary>
    public class WeeklyResourceDemand
    {
        public DateTime WeekStartDate { get; set; }
        public DateTime WeekEndDate { get; set; }
        public int RequiredPersonnelCount { get; set; }
        public int AvailablePersonnelCount { get; set; }
        public int RequiredEquipmentCount { get; set; }
        public int AvailableEquipmentCount { get; set; }
        public decimal EstimatedWorkHours { get; set; }
        public bool IsSufficient => AvailablePersonnelCount >= RequiredPersonnelCount && 
                                   AvailableEquipmentCount >= RequiredEquipmentCount;
    }
    
    /// <summary>
    /// 项目资源对比结果
    /// </summary>
    public class ProjectResourceComparisonResult
    {
        /// <summary>
        /// 对比维度
        /// </summary>
        public string ComparisonDimension { get; set; }
        
        /// <summary>
        /// 对比时间范围
        /// </summary>
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        
        /// <summary>
        /// 项目资源对比详情
        /// </summary>
        public List<ProjectResourceComparison> ProjectComparisons { get; set; } = new();
        
        /// <summary>
        /// 总体资源充足性
        /// </summary>
        public bool OverallSufficiency { get; set; }
        
        /// <summary>
        /// 资源紧张度评分（0-100，100表示资源非常紧张）
        /// </summary>
        public int ResourceTensionScore { get; set; }
    }
    
    /// <summary>
    /// 项目资源对比
    /// </summary>
    public class ProjectResourceComparison
    {
        public string ProjectNumber { get; set; }
        public string ProjectName { get; set; }
        public int TotalTaskCount { get; set; }
        public decimal? TotalEstimatedHours { get; set; }
        public int PeakPersonnelDemand { get; set; }
        public int AvailablePersonnelCapacity { get; set; }
        public int PeakEquipmentDemand { get; set; }
        public int AvailableEquipmentCapacity { get; set; }
        public string ResourceStatus { get; set; } // "充足"、"紧张"、"不足"
        public List<string> Recommendations { get; set; } = new();
    }
}