using Hotline.Share.Dtos.File;
using Hotline.Share.Enums.FlowEngine;
using XF.Utility.EnumExtensions;

namespace Hotline.Share.Dtos.FlowEngine.Workflow;

public class WorkflowTraceDto : StepBasicDto
{
    public string Id { get; set; }
    
    /// <summary>
    /// 节点Id
    /// </summary>
    public string StepId { get; set; }

    /// <summary>
    /// 流转记录状态
    /// </summary>
    public EWorkflowTraceType TraceType { get; set; }
    
    public string TraceTypeText => TraceType.GetDescription();

    /// <summary>
    /// 过期时间（生成流转记录时取值当前workflow的过期时间）
    /// </summary>
    public DateTime ExpiredTime { get; set; }

    /// <summary>
    /// 会签从属关系
    /// </summary>
    public string? ParentId { get; set; }

    /// <summary>
    /// 派单组办理次数
    /// </summary>
    public int SendHandleTimes { get; set; }

    /// <summary>
    /// 会签流转记录
    /// </summary>
    public List<WorkflowTraceDto> Traces { get; set; }

    public List<FileDto>? Files { get; set; }

	public ExpiredStatus ExpiredStatus
    {
        get
        {
            if (HandleTime.HasValue)
            {
                return HandleTime.Value < StepExpiredTime ? ExpiredStatus.Completed : ExpiredStatus.Expired;
            }
            else
            {
                return DateTime.Now < StepExpiredTime ? ExpiredStatus.Handling : ExpiredStatus.Expired;
            }
        }
    }

    public string ExpiredStatusText => ExpiredStatus.GetDescription();
}