using GxPress.Entity;
using GxPress.Entity.WorkFlow;
using GxPress.Entity.WorkProcess;
using GxPress.EnumConst;

namespace GxPress.Service.Implement
{
    public partial class FlowService
    {
        public string GetFlowName(User user, Process process)
        {
            if (user != null && process != null)
            {
                return $"{user.Name}提交的{process.Name}申请";
            }

            return "未知申请";
        }

        public string GetFieldValue(FlowFieldValue value)
        {
            if (value == null) return string.Empty;

            if (value.FieldType == nameof(FieldTypeConst.Number) || value.FieldType == nameof(FieldTypeConst.Currency))
            {
                return value.IntValue.ToString();
            }
            if (value.FieldType == nameof(FieldTypeConst.Radio))
            {
                return value.StringValues;
            }

            return value.StringValue;
        }

        public string GetTodoAction(FlowTodo todo)
        {
            if (todo.Type == nameof(TodoTypeConst.ApproverCheck))
            {
                if (!todo.IsDone && !todo.IsChecked && todo.IsOperate)
                {
                    return NodeStateConstUtils.GetText(NodeStateConst.Checking);
                }
                else if (!todo.IsDone && !todo.IsChecked && !todo.IsOperate)
                {
                    return "";
                }
                else if (todo.IsDone && !todo.IsChecked)
                {
                    if (todo.DoneType == 1)
                        return "上会";
                    else if (todo.DoneType == 2)
                        return "待定";
                    return NodeStateConstUtils.GetText(NodeStateConst.Denied);

                }
                else if (todo.IsDone && todo.IsChecked && todo.IsReferral)
                {
                    return NodeStateConstUtils.GetText(NodeStateConst.Referral);
                }
                else if (todo.IsDone && todo.IsChecked)
                {
                    return NodeStateConstUtils.GetText(NodeStateConst.Checked);
                }
                return todo.IsChecked ? NodeStateConstUtils.GetText(NodeStateConst.Checked) : NodeStateConstUtils.GetText(NodeStateConst.Denied);
            }

            //if (todo.Type == nameof(TodoTypeConst.ApproverCheck))
            //{
            //    return todo.IsDone ? NodeStateConstUtils.GetText(NodeStateConst.Checked) : NodeStateConstUtils.GetText(NodeStateConst.Denied);
            //}

            return string.Empty;
        }
    }
}