using System;
using System.Collections.Generic;

namespace NPP.SmartSchedue.Api.Contracts.Services.Equipment.Dto;

/// <summary>
/// 按设备类型统计输出模型
/// 包含设备数量、状态分布等核心统计信息
/// </summary>
public class EquipmentTypeStatisticsOutput
{
    /// <summary>
    /// 设备类型（Production, Testing, Laboratory, Office, Other）
    /// </summary>
    public string EquipmentType { get; set; } = string.Empty;

    /// <summary>
    /// 设备类型显示名称
    /// </summary>
    public string EquipmentTypeName { get; set; } = string.Empty;

    /// <summary>
    /// 总设备数量
    /// </summary>
    public int TotalCount { get; set; }

    /// <summary>
    /// 按状态分组的设备数量统计
    /// 业务深度思考：涵盖设备全生命周期状态，支持设备管理决策
    /// </summary>
    public EquipmentStatusDistribution StatusDistribution { get; set; } = new();

    /// <summary>
    /// 平均设备使用年限（年）
    /// </summary>
    public decimal AverageServiceYears { get; set; }

    /// <summary>
    /// 设备价值统计（总价值、平均单价）
    /// </summary>
    public EquipmentValueStatistics ValueStatistics { get; set; } = new();

    /// <summary>
    /// 最近维护信息汇总
    /// </summary>
    public MaintenanceSummary MaintenanceSummary { get; set; } = new();
}

/// <summary>
/// 设备状态分布统计
/// 深度业务场景：支持设备健康度评估和维护规划
/// </summary>
public class EquipmentStatusDistribution
{
    /// <summary>
    /// 正常状态设备数量
    /// </summary>
    public int NormalCount { get; set; }

    /// <summary>
    /// 维护中设备数量
    /// </summary>
    public int MaintenanceCount { get; set; }

    /// <summary>
    /// 校验中设备数量
    /// </summary>
    public int CalibrationCount { get; set; }

    /// <summary>
    /// 故障设备数量
    /// </summary>
    public int FaultCount { get; set; }

    /// <summary>
    /// 报废设备数量
    /// </summary>
    public int ScrapCount { get; set; }

    /// <summary>
    /// 停用设备数量
    /// </summary>
    public int InactiveCount { get; set; }

    /// <summary>
    /// 设备健康度百分比（正常设备占比）
    /// </summary>
    public decimal HealthPercentage => TotalActiveCount > 0 ? 
        (decimal)NormalCount / TotalActiveCount * 100 : 0;

    /// <summary>
    /// 活跃设备总数（排除报废和停用）
    /// </summary>
    public int TotalActiveCount => NormalCount + MaintenanceCount + CalibrationCount + FaultCount;
}

/// <summary>
/// 设备价值统计
/// 业务深度思考：支持资产管理和投资回报分析
/// </summary>
public class EquipmentValueStatistics
{
    /// <summary>
    /// 总资产价值
    /// </summary>
    public decimal TotalValue { get; set; }

    /// <summary>
    /// 平均单台价值
    /// </summary>
    public decimal AverageValue { get; set; }

    /// <summary>
    /// 最高单台价值
    /// </summary>
    public decimal MaxValue { get; set; }

    /// <summary>
    /// 最低单台价值
    /// </summary>
    public decimal MinValue { get; set; }
}

/// <summary>
/// 维护信息汇总
/// 深度业务场景：支持维护成本分析和维护策略优化
/// </summary>
public class MaintenanceSummary
{
    /// <summary>
    /// 最近30天内维护次数
    /// </summary>
    public int RecentMaintenanceCount { get; set; }

    /// <summary>
    /// 平均维护间隔天数
    /// </summary>
    public decimal AverageMaintenanceInterval { get; set; }

    /// <summary>
    /// 下次预计维护日期
    /// </summary>
    public DateTime? NextMaintenanceDate { get; set; }

    /// <summary>
    /// 维护成本趋势（相比上期增长百分比）
    /// </summary>
    public decimal MaintenanceCostTrend { get; set; }
}