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 GridDataOutput
{
    /// <summary>
    /// 网格数据：日期 -> (班次ID -> 单元格数据) 的嵌套字典
    /// </summary>
    public Dictionary<DateTime, Dictionary<long, CellData>> Grid { get; set; } = new();

    /// <summary>
    /// 班次信息列表
    /// </summary>
    public List<ShiftInfo> Shifts { get; set; } = new();

    /// <summary>
    /// 日期列表（按顺序）
    /// </summary>
    public List<DateTime> Dates { get; set; } = new();

    /// <summary>
    /// 统计信息
    /// </summary>
    public GridStatistics Statistics { get; set; } = new();

    /// <summary>
    /// 月份信息
    /// </summary>
    public string MonthDisplay { get; set; }

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

/// <summary>
/// 网格单元格数据
/// </summary>
public class CellData
{
    /// <summary>
    /// 是否不可用
    /// </summary>
    public bool IsUnavailable { get; set; }

    /// <summary>
    /// 不可用原因类型（如果不可用）
    /// </summary>
    public UnavailabilityReasonType? ReasonType { get; set; }

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

    /// <summary>
    /// CSS样式类名
    /// </summary>
    public string CssClass { get; set; }

    /// <summary>
    /// 备注信息
    /// </summary>
    public string Remark { get; set; }

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

    /// <summary>
    /// 是否为模板生成
    /// </summary>
    public bool IsFromTemplate { get; set; }

    /// <summary>
    /// 记录ID（用于编辑操作）
    /// </summary>
    public long? RecordId { get; set; }

    /// <summary>
    /// 工具提示文本
    /// </summary>
    public string TooltipText { get; set; }
}

/// <summary>
/// 班次信息
/// </summary>
public class ShiftInfo
{
    /// <summary>
    /// 班次ID
    /// </summary>
    public long Id { get; set; }

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

    /// <summary>
    /// 班次编号
    /// </summary>
    public int ShiftNumber { get; set; }

    /// <summary>
    /// 开始时间
    /// </summary>
    public TimeSpan StartTime { get; set; }

    /// <summary>
    /// 结束时间
    /// </summary>
    public TimeSpan EndTime { get; set; }

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

    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsEnabled { get; set; }
}

/// <summary>
/// 网格统计信息
/// </summary>
public class GridStatistics
{
    /// <summary>
    /// 总不可用次数
    /// </summary>
    public int TotalCount { get; set; }

    /// <summary>
    /// 按班次统计：班次ID -> 不可用次数
    /// </summary>
    public Dictionary<long, int> ShiftCounts { get; set; } = new();

    /// <summary>
    /// 按原因类型统计：原因类型 -> 不可用次数
    /// </summary>
    public Dictionary<UnavailabilityReasonType, int> ReasonTypeCounts { get; set; } = new();

    /// <summary>
    /// 按分组统计：分组 -> 不可用次数
    /// </summary>
    public Dictionary<UnavailabilityCategory, int> CategoryCounts { get; set; } = new();

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

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

/// <summary>
/// 员工信息
/// </summary>
public class PersonnelInfo
{
    /// <summary>
    /// 员工ID
    /// </summary>
    public long Id { get; set; }

    /// <summary>
    /// 员工姓名
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// 员工工号
    /// </summary>
    public string Code { get; set; }

    /// <summary>
    /// 部门名称
    /// </summary>
    public string DepartmentName { get; set; }

    /// <summary>
    /// 职位名称
    /// </summary>
    public string PositionName { get; set; }
}