using FluentValidation;
using TakeoutSaaS.Application.App.Stores.Commands;
using TakeoutSaaS.Domain.Stores.Enums;

namespace TakeoutSaaS.Application.App.Stores.Validators;

/// <summary>
/// 切换门店经营状态命令验证器。
/// </summary>
public sealed class ToggleBusinessStatusCommandValidator : AbstractValidator<ToggleBusinessStatusCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public ToggleBusinessStatusCommandValidator()
    {
        RuleFor(x => x.StoreId).GreaterThan(0);
        RuleFor(x => x.BusinessStatus)
            .Must(status => status is StoreBusinessStatus.Open or StoreBusinessStatus.Resting)
            .WithMessage("仅允许切换营业中或休息中");

        RuleFor(x => x.ClosureReason)
            .NotNull()
            .When(x => x.BusinessStatus == StoreBusinessStatus.Resting)
            .WithMessage("切换休息中必须选择歇业原因");

        RuleFor(x => x.ClosureReasonText).MaximumLength(500);
    }
}
