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

namespace TakeoutSaaS.Application.App.Stores.Validators;

/// <summary>
/// 创建节假日命令验证器。
/// </summary>
public sealed class CreateStoreHolidayCommandValidator : AbstractValidator<CreateStoreHolidayCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public CreateStoreHolidayCommandValidator()
    {
        RuleFor(x => x.StoreId).GreaterThan(0);
        RuleFor(x => x.Date).NotEmpty();

        RuleFor(x => x.EndDate)
            .GreaterThanOrEqualTo(x => x.Date)
            .When(x => x.EndDate.HasValue)
            .WithMessage("结束日期不能早于开始日期");

        RuleFor(x => x.StartTime)
            .NotNull()
            .When(x => !x.IsAllDay)
            .WithMessage("非全天模式下必须填写开始时间");

        RuleFor(x => x.EndTime)
            .NotNull()
            .When(x => !x.IsAllDay)
            .WithMessage("非全天模式下必须填写结束时间");

        RuleFor(x => x.EndTime)
            .GreaterThan(x => x.StartTime)
            .When(x => !x.IsAllDay && x.StartTime.HasValue && x.EndTime.HasValue)
            .WithMessage("结束时间必须晚于开始时间");

        RuleFor(x => x.Reason).MaximumLength(200);
    }
}
