using System;
using System.Collections.Generic;

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

/// <summary>
/// 任务自检结果
/// </summary>
public class WorkOrderValidationOutput
{
    /// <summary>
    /// 任务ID
    /// </summary>
    public long WorkOrderId { get; set; }

    /// <summary>
    /// 任务名称
    /// </summary>
    public string WorkOrderCode { get; set; }

    /// <summary>
    /// 总体验证是否通过
    /// </summary>
    public bool IsValid { get; set; }

    /// <summary>
    /// 验证错误列表
    /// </summary>
    public List<WorkOrderValidationError> Errors { get; set; } = new();

    /// <summary>
    /// 人员空闲状态检查结果
    /// </summary>
    public List<PersonnelAvailabilityResult> PersonnelResults { get; set; } = new();
}

/// <summary>
/// 多任务自检结果
/// </summary>
public class MultipleWorkOrderValidationOutput
{
    /// <summary>
    /// 总体验证是否通过
    /// </summary>
    public bool IsValid { get; set; }

    /// <summary>
    /// 各任务验证结果
    /// </summary>
    public List<WorkOrderValidationOutput> WorkOrderResults { get; set; } = new();

    /// <summary>
    /// 跨任务冲突检查结果
    /// </summary>
    public List<WorkOrderValidationError> CrossTaskConflicts { get; set; } = new();
}

/// <summary>
/// 工作任务验证错误信息
/// </summary>
public class WorkOrderValidationError
{
    /// <summary>
    /// 错误类型
    /// </summary>
    public ValidationErrorType ErrorType { get; set; }

    /// <summary>
    /// 错误信息
    /// </summary>
    public string Message { get; set; }

    /// <summary>
    /// 相关人员ID
    /// </summary>
    public long? PersonnelId { get; set; }

    /// <summary>
    /// 相关人员姓名
    /// </summary>
    public string PersonnelName { get; set; }
}

/// <summary>
/// 人员空闲状态检查结果
/// </summary>
public class PersonnelAvailabilityResult
{
    /// <summary>
    /// 人员ID
    /// </summary>
    public long PersonnelId { get; set; }

    /// <summary>
    /// 人员姓名
    /// </summary>
    public string PersonnelName { get; set; }

    /// <summary>
    /// 是否空闲可用
    /// </summary>
    public bool IsAvailable { get; set; }

    /// <summary>
    /// 请假冲突
    /// </summary>
    public bool HasLeaveConflict { get; set; }

    /// <summary>
    /// 任务时间冲突
    /// </summary>
    public bool HasTaskTimeConflict { get; set; }

    /// <summary>
    /// 工作时间限制冲突
    /// </summary>
    public bool HasWorkLimitConflict { get; set; }

    /// <summary>
    /// 冲突详情
    /// </summary>
    public List<string> ConflictDetails { get; set; } = new();
}

/// <summary>
/// 验证错误类型
/// </summary>
public enum ValidationErrorType
{
    /// <summary>
    /// 人员请假冲突
    /// </summary>
    PersonnelLeaveConflict = 1,

    /// <summary>
    /// 任务时间冲突
    /// </summary>
    TaskTimeConflict = 2,

    /// <summary>
    /// 工作时间限制冲突
    /// </summary>
    WorkLimitConflict = 3,

    /// <summary>
    /// 连续工作时间超限
    /// </summary>
    ContinuousWorkTimeExceeded = 4,

    /// <summary>
    /// 班次规则冲突
    /// </summary>
    ShiftRuleConflict = 5
}