using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ZhonTai.Admin.Core.Repositories;

namespace NPP.SmartSchedue.Api.Contracts.Domain.Equipment;

/// <summary>
/// 设备仓储接口
/// </summary>
public interface IEquipmentRepository : IRepositoryBase<EquipmentEntity>
{
    /// <summary>
    /// 根据设备类型获取设备列表
    /// </summary>
    /// <param name="equipmentType">设备类型</param>
    /// <returns>设备列表</returns>
    Task<List<EquipmentEntity>> GetByTypeAsync(string equipmentType);

    /// <summary>
    /// 根据状态获取设备列表
    /// </summary>
    /// <param name="status">设备状态</param>
    /// <returns>设备列表</returns>
    Task<List<EquipmentEntity>> GetByStatusAsync(int status);

    /// <summary>
    /// 根据内部编号获取设备
    /// </summary>
    /// <param name="internalNumber">内部编号</param>
    /// <returns>设备信息</returns>
    Task<EquipmentEntity> GetByInternalNumberAsync(string internalNumber);

    /// <summary>
    /// 获取可用设备列表（正常状态）
    /// </summary>
    /// <param name="date">指定日期</param>
    /// <returns>可用设备列表</returns>
    Task<List<EquipmentEntity>> GetAvailableEquipmentAsync(DateTime date);

    /// <summary>
    /// 根据工序获取适配设备列表
    /// </summary>
    /// <param name="processName">工序名称</param>
    /// <returns>适配设备列表</returns>
    Task<List<EquipmentEntity>> GetByProcessAsync(string processName);

    /// <summary>
    /// 检查设备是否可用
    /// </summary>
    /// <param name="equipmentId">设备ID</param>
    /// <param name="date">指定日期</param>
    /// <returns>是否可用</returns>
    Task<bool> IsEquipmentAvailableAsync(long equipmentId, DateTime date);

    /// <summary>
    /// 获取设备使用情况
    /// </summary>
    /// <param name="equipmentId">设备ID</param>
    /// <param name="startDate">开始日期</param>
    /// <param name="endDate">结束日期</param>
    /// <returns>设备使用情况</returns>
    Task<EquipmentUsageInfo> GetUsageAsync(long equipmentId, DateTime startDate, DateTime endDate);

    /// <summary>
    /// 获取需要维护的设备列表
    /// </summary>
    /// <param name="date">指定日期</param>
    /// <returns>需要维护的设备列表</returns>
    Task<List<EquipmentEntity>> GetNeedMaintenanceAsync(DateTime date);

    /// <summary>
    /// 获取需要校验的设备列表
    /// </summary>
    /// <param name="date">指定日期</param>
    /// <returns>需要校验的设备列表</returns>
    Task<List<EquipmentEntity>> GetNeedCalibrationAsync(DateTime date);

    /// <summary>
    /// 检查指定设备类型是否有可用设备
    /// </summary>
    /// <param name="equipmentType">设备类型</param>
    /// <returns>是否有可用设备</returns>
    Task<bool> HasAvailableEquipmentByTypeAsync(string equipmentType);
}

/// <summary>
/// 设备使用情况信息
/// </summary>
public class EquipmentUsageInfo
{
    /// <summary>
    /// 设备ID
    /// </summary>
    public long EquipmentId { get; set; }

    /// <summary>
    /// 设备名称
    /// </summary>
    public string EquipmentName { get; set; }

    /// <summary>
    /// 使用天数
    /// </summary>
    public int UsageDays { get; set; }

    /// <summary>
    /// 使用小时数
    /// </summary>
    public int UsageHours { get; set; }

    /// <summary>
    /// 维护次数
    /// </summary>
    public int MaintenanceCount { get; set; }

    /// <summary>
    /// 校验次数
    /// </summary>
    public int CalibrationCount { get; set; }

    /// <summary>
    /// 故障次数
    /// </summary>
    public int FaultCount { get; set; }
}