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

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

/// <summary>
/// 不可用统计信息输出模型
/// 提供各种维度的统计数据
/// </summary>
public class UnavailabilityStatistics
{
    /// <summary>
    /// 员工ID
    /// </summary>
    public long PersonnelId { get; set; }

    /// <summary>
    /// 开始日期
    /// </summary>
    public DateTime StartDate { get; set; }

    /// <summary>
    /// 结束日期
    /// </summary>
    public DateTime EndDate { get; set; }

    /// <summary>
    /// 总天数
    /// </summary>
    public int TotalDays { get; set; }

    /// <summary>
    /// 总记录数
    /// </summary>
    public int TotalRecords { get; set; }

    /// <summary>
    /// 总可能时段数
    /// </summary>
    public int TotalPossibleSlots { get; set; }

    /// <summary>
    /// 员工信息
    /// </summary>
    public PersonnelInfo Personnel { get; set; }

    /// <summary>
    /// 统计时间范围
    /// </summary>
    public StatisticsDateRange DateRange { get; set; }

    /// <summary>
    /// 总体统计
    /// </summary>
    public OverallStatistics Overall { get; set; } = new();

    /// <summary>
    /// 按班次统计
    /// </summary>
    public List<ShiftStatistics> ShiftStats { get; set; } = new();

    /// <summary>
    /// 班次统计（与ShiftStats相同，用于兼容性）
    /// </summary>
    public List<ShiftStatistics> ShiftStatistics { get; set; } = new();

    /// <summary>
    /// 按原因类型统计
    /// </summary>
    public List<ReasonTypeStatistics> ReasonTypeStats { get; set; } = new();

    /// <summary>
    /// 原因类型统计（与ReasonTypeStats相同，用于兼容性）
    /// </summary>
    public List<ReasonTypeStatistics> ReasonTypeStatistics { get; set; } = new();

    /// <summary>
    /// 按分组统计
    /// </summary>
    public List<CategoryStatistics> CategoryStats { get; set; } = new();

    /// <summary>
    /// 分组统计（与CategoryStats相同，用于兼容性）
    /// </summary>
    public List<CategoryStatistics> CategoryStatistics { get; set; } = new();

    /// <summary>
    /// 按月份统计
    /// </summary>
    public List<MonthlyStatistics> MonthlyStats { get; set; } = new();

    /// <summary>
    /// 按星期统计
    /// </summary>
    public List<WeekdayStatistics> WeekdayStats { get; set; } = new();

    /// <summary>
    /// 星期统计（与WeekdayStats相同，用于兼容性）
    /// </summary>
    public List<WeekdayStatistics> WeekdayStatistics { get; set; } = new();

    /// <summary>
    /// 模板生成统计
    /// </summary>
    public TemplateStatistics TemplateStatistics { get; set; } = new();

    /// <summary>
    /// 月度趋势分析
    /// </summary>
    public List<MonthlyTrendItem> MonthlyTrend { get; set; } = new();

    /// <summary>
    /// 不可用率（百分比）
    /// </summary>
    public double UnavailableRate { get; set; }
}

/// <summary>
/// 统计时间范围
/// </summary>
public class StatisticsDateRange
{
    /// <summary>
    /// 开始日期
    /// </summary>
    public DateTime StartDate { get; set; }

    /// <summary>
    /// 结束日期
    /// </summary>
    public DateTime EndDate { get; set; }

    /// <summary>
    /// 时间范围显示
    /// </summary>
    public string Display { get; set; }

    /// <summary>
    /// 总天数
    /// </summary>
    public int TotalDays { get; set; }
}

/// <summary>
/// 总体统计
/// </summary>
public class OverallStatistics
{
    /// <summary>
    /// 总不可用次数
    /// </summary>
    public int TotalCount { get; set; }

    /// <summary>
    /// 不可用天数
    /// </summary>
    public int UnavailableDays { get; set; }

    /// <summary>
    /// 不可用率（百分比）
    /// </summary>
    public decimal UnavailabilityRate { get; set; }

    /// <summary>
    /// 模板生成数量
    /// </summary>
    public int TemplateGeneratedCount { get; set; }

    /// <summary>
    /// 手动创建数量
    /// </summary>
    public int ManualCreatedCount { get; set; }

    /// <summary>
    /// 平均每天不可用班次数
    /// </summary>
    public decimal AverageUnavailableShiftsPerDay { get; set; }
}

/// <summary>
/// 班次统计
/// </summary>
public class ShiftStatistics
{
    /// <summary>
    /// 班次ID
    /// </summary>
    public long ShiftId { get; set; }

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

    /// <summary>
    /// 班次时间范围
    /// </summary>
    public string TimeRange { get; set; }

    /// <summary>
    /// 不可用次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 占比（百分比）
    /// </summary>
    public decimal Percentage { get; set; }

    /// <summary>
    /// 排名
    /// </summary>
    public int Rank { get; set; }
}

/// <summary>
/// 原因类型统计
/// </summary>
public class ReasonTypeStatistics
{
    /// <summary>
    /// 原因类型
    /// </summary>
    public UnavailabilityReasonType ReasonType { get; set; }

    /// <summary>
    /// 原因类型名称
    /// </summary>
    public string ReasonTypeName { get; set; }

    /// <summary>
    /// 分组
    /// </summary>
    public UnavailabilityCategory Category { get; set; }

    /// <summary>
    /// 显示符号
    /// </summary>
    public string Symbol { get; set; }

    /// <summary>
    /// 颜色类
    /// </summary>
    public string ColorClass { get; set; }

    /// <summary>
    /// 不可用次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 占比（百分比）
    /// </summary>
    public decimal Percentage { get; set; }

    /// <summary>
    /// 影响天数
    /// </summary>
    public int AffectedDays { get; set; }

    /// <summary>
    /// 排名
    /// </summary>
    public int Rank { get; set; }
}

/// <summary>
/// 分组统计
/// </summary>
public class CategoryStatistics
{
    /// <summary>
    /// 分组类型
    /// </summary>
    public UnavailabilityCategory Category { get; set; }

    /// <summary>
    /// 分组名称
    /// </summary>
    public string CategoryName { get; set; }

    /// <summary>
    /// 不可用次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 占比（百分比）
    /// </summary>
    public decimal Percentage { get; set; }

    /// <summary>
    /// 影响天数
    /// </summary>
    public int AffectedDays { get; set; }

    /// <summary>
    /// 包含的原因类型列表
    /// </summary>
    public List<UnavailabilityReasonType> ReasonTypes { get; set; } = new();
}

/// <summary>
/// 月份统计
/// </summary>
public class MonthlyStatistics
{
    /// <summary>
    /// 年月
    /// </summary>
    public DateTime Month { get; set; }

    /// <summary>
    /// 月份显示
    /// </summary>
    public string MonthDisplay { get; set; }

    /// <summary>
    /// 不可用次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 不可用天数
    /// </summary>
    public int UnavailableDays { get; set; }

    /// <summary>
    /// 该月总天数
    /// </summary>
    public int TotalDays { get; set; }

    /// <summary>
    /// 不可用率
    /// </summary>
    public decimal UnavailabilityRate { get; set; }
}

/// <summary>
/// 星期统计
/// </summary>
public class WeekdayStatistics
{
    /// <summary>
    /// 星期几 (0=周日, 1=周一, ..., 6=周六)
    /// </summary>
    public int Weekday { get; set; }

    /// <summary>
    /// 星期几（DayOfWeek枚举）
    /// </summary>
    public DayOfWeek DayOfWeek { get; set; }

    /// <summary>
    /// 星期显示名称
    /// </summary>
    public string WeekdayName { get; set; }

    /// <summary>
    /// 星期名称（简短）
    /// </summary>
    public string DayName { get; set; }

    /// <summary>
    /// 不可用次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 占比（百分比）
    /// </summary>
    public decimal Percentage { get; set; }

    /// <summary>
    /// 涉及的日期数
    /// </summary>
    public int AffectedDates { get; set; }
}

/// <summary>
/// 模板生成统计
/// </summary>
public class TemplateStatistics
{
    /// <summary>
    /// 总模板记录数
    /// </summary>
    public int TotalTemplateRecords { get; set; }

    /// <summary>
    /// 模板生成率
    /// </summary>
    public decimal TemplateGeneratedRate { get; set; }

    /// <summary>
    /// 手动创建记录数
    /// </summary>
    public int ManualCreatedRecords { get; set; }

    /// <summary>
    /// 手动创建率
    /// </summary>
    public decimal ManualCreatedRate { get; set; }
}

/// <summary>
/// 月度趋势项目
/// </summary>
public class MonthlyTrendItem
{
    /// <summary>
    /// 年份
    /// </summary>
    public int Year { get; set; }

    /// <summary>
    /// 月份
    /// </summary>
    public int Month { get; set; }

    /// <summary>
    /// 月份显示
    /// </summary>
    public string MonthDisplay { get; set; }

    /// <summary>
    /// 不可用次数
    /// </summary>
    public int Count { get; set; }

    /// <summary>
    /// 不可用天数
    /// </summary>
    public int UnavailableDays { get; set; }

    /// <summary>
    /// 不可用率
    /// </summary>
    public decimal UnavailabilityRate { get; set; }

    /// <summary>
    /// 环比变化率
    /// </summary>
    public decimal? ChangeRate { get; set; }
}