using FluentValidation;
using Hotline.Share.Dtos.FlowEngine.Workflow;
using Hotline.Share.Enums.FlowEngine;

namespace Hotline.Validators.FlowEngine
{
    public class BasicWorkflowDtoValidator : AbstractValidator<BasicWorkflowDto>
    {
        public BasicWorkflowDtoValidator()
        {
            RuleFor(d => d.BusinessType).NotNull();
            RuleFor(d => d.HandlerType).NotNull();
            //RuleFor(d => d.Opinion)
            //    .Cascade(CascadeMode.Stop)
            //    .NotEmpty()
            //    .MaximumLength(4000);
        }
    }

    public class StepAssignInfoValidator : AbstractValidator<StepAssignInfo>
    {
        public StepAssignInfoValidator()
        {
            RuleFor(d=>d.FlowAssignType).NotNull();
            RuleFor(d=>d.UserId).NotNull().When(d=>d.FlowAssignType == EFlowAssignType.User);
            RuleFor(d=>d.Username).NotNull().When(d=>d.FlowAssignType == EFlowAssignType.User);
            RuleFor(d=>d.OrgId).NotNull().When(d=>d.FlowAssignType == EFlowAssignType.Org || d.FlowAssignType == EFlowAssignType.OrgAndRole);
            RuleFor(d=>d.OrgName).NotNull().When(d => d.FlowAssignType == EFlowAssignType.Org|| d.FlowAssignType == EFlowAssignType.OrgAndRole);
            RuleFor(d=>d.RoleId).NotNull().When(d=>d.FlowAssignType == EFlowAssignType.Role|| d.FlowAssignType == EFlowAssignType.OrgAndRole);
            RuleFor(d=>d.RoleName).NotNull().When(d => d.FlowAssignType == EFlowAssignType.Role|| d.FlowAssignType == EFlowAssignType.OrgAndRole);
        }
    }
}
