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

namespace Hotline.Share.Dtos.FlowEngine.Workflow
{
    public class StepBasicDto
    {
        public string WorkflowId { get; set; }

        /// <summary>
        /// 该节点指派办理对象（依据不同指派方式可能为：orgId或userId）,该字段subStep才会存在，stepBox不存在
        /// 采用list类型，兼容多个办理对象可以办理同一个节点的场景
        /// </summary>
        public List<Kv> Handlers { get; set; } = new();


        /// <summary>
        /// 办理时间限制(如：24小时、7个工作日)
        /// </summary>
        public string? TimeLimit { get; set; }

        /// <summary>
        /// 上一节点办理时，nextStepCode下拉框中选中的值
        /// config模式：当前节点的difinition.code, dynamic模式：x级部门办理的x：int
        /// </summary>
        public string? PrevChosenStepCode { get; set; }

        #region 交办

        /// <summary>
        /// 交办人
        /// </summary>
        public string? AssignerId { get; set; }

        public string? AssignerName { get; set; }

        /// <summary>
        /// 交办人部门Id
        /// </summary>
        public string? AssignerOrgId { get; set; }

        public string? AssignerOrgName { get; set; }

        public bool? AssignerOrgIsCenter { get; set; }

        #endregion

        #region 接办

        /// <summary>
        /// 接办人
        /// </summary>
        public string? AcceptorId { get; set; }

        public string? AcceptorName { get; set; }

        /// <summary>
        /// 接办人部门code
        /// </summary>
        public string? AcceptorOrgId { get; set; }

        public string? AcceptorOrgName { get; set; }

        /// <summary>
        /// 接办人部门行政区划代码
        /// </summary>
        public string? AcceptorOrgAreaCode { get; set; }

        /// <summary>
        /// 接办人部门行政区划名称
        /// </summary>
        public string? AcceptorOrgAreaName { get; set; }

        /// <summary>
        /// 接办时间
        /// </summary>
        public DateTime? AcceptTime { get; set; }

        #endregion

        #region 办理

        /// <summary>
        /// 办理人
        /// </summary>
        public string? HandlerId { get; set; }

        public string? HandlerName { get; set; }

        /// <summary>
        /// 办理人部门code
        /// </summary>
        public string? HandlerOrgId { get; set; }

        /// <summary>
        /// 办理人部门名称
        /// </summary>
        public string? HandlerOrgName { get; set; }

        /// <summary>
        /// 办理人部门行政区划代码
        /// </summary>
        public string? HandlerOrgAreaCode { get; set; }

        /// <summary>
        /// 办理人部门行政区划名称
        /// </summary>
        public string? HandlerOrgAreaName { get; set; }

        /// <summary>
        /// 办理完成时间
        /// </summary>
        public DateTime? HandleTime { get; set; }

        /// <summary>
        /// 办理方式
        /// </summary>
        public EHandleMode? HandleMode { get; set; }

        public string? HandleModeText => HandleMode.HasValue ? HandleMode.GetDescription() : "";

        /// <summary>
        /// 审核结果（非审批流程无意义）
        /// </summary>
        public EReviewResult ReviewResult { get; set; }

        public string ReviewResultText => ReviewResult.GetDescription();

        #endregion

        #region Definition

        public string Name { get; set; }

        /// <summary>
        /// 模板内唯一
        /// </summary>
        public string Code { get; set; }

        public EStepType StepType { get; init; }

        /// <summary>
        /// 节点业务类型
        /// </summary>
        public EBusinessType BusinessType { get; set; }

        /// <summary>
        /// 办理人类型
        /// </summary>
        public EHandlerType HandlerType { get; set; }

        /// <summary>
        /// 是否有否决按钮
        /// </summary>
        public bool CanReject { get; set; }

        /// <summary>
        /// 执行模式(自动与否)
        /// 只有普通节点支持自动，会签、动态节点均不支持自动
        /// </summary>
        public EExecuteMode ExecuteMode { get; set; }

        #region 会签相关配置

        /// <summary>
        /// 是否支持发起会签（即使支持发起，当下一节点为汇总或结束节点时亦不可发起）
        /// </summary>
        public bool CanStartCountersign { get; set; }

        /// <summary>
        /// 会签策略
        /// </summary>
        public ECountersignPolicy? CountersignPolicy { get; set; }

        #endregion

        #region 依据配置生成节点的方式

        /// <summary>
        /// 实例化模式
        /// </summary>
        public EInstanceMode InstanceMode { get; set; }

        /// <summary>
        /// 动态实例化策略(多次模式才有)
        /// </summary>
        public EDynamicPolicy? InstancePolicy { get; set; }

        /// <summary>
        /// 到此标记终止动态实例化(多次模式才有)
        /// <remarks>
        /// 按直属部门重复既保存orgLevel:int
        /// </remarks>
        /// </summary>
        public string? TerminalDynamicMark { get; set; }

        #endregion

        /// <summary>
        /// 标签
        /// </summary>
        public string? Tag { get; set; }

        #endregion

        #region 办理参数

        /// <summary>
        /// (下一节点办理人)根据审批者类型不同，此字段为不同内容
        /// <example>
        /// 部门等级/分类为：orgCodes, 角色为：userIds
        /// </example>
        /// </summary>
        public List<Kv> NextHandlers { get; set; } = new();

        /// <summary>
        /// 下一节点主办，(NextHandlers其中一个, 如果不是会签则只有一个)
        /// </summary>
        public string? NextMainHandler { get; set; }

        /// <summary>
        /// 下一节点code（stepBox无值）
        /// </summary>
        public string? NextStepCode { get; set; }

        /// <summary>
        /// 是否回到会签发起节点汇总
        /// </summary>
        public bool BackToCountersignEnd { get; set; }

        /// <summary>
        /// 是否短信通知
        /// </summary>
        public bool IsSms { get; set; }

        /// <summary>
        /// 办理意见
        /// </summary>
        public string? Opinion { get; set; }

        /// <summary>
        /// 附件
        /// </summary>
        public List<FileJson>? FileJson { get; set; }

        /// <summary>
        /// 节点期满时间
        /// </summary>
        public DateTime? StepExpiredTime { get; set; }

        #endregion

        #region method

        /// <summary>
        /// 办理对象
        /// </summary>
        public string? Handler { get; set; }

        #endregion
    }
}
