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

namespace TakeoutSaaS.Application.App.Stores.Validators;

/// <summary>
/// 更新门店资质命令验证器。
/// </summary>
public sealed class UpdateStoreQualificationCommandValidator : AbstractValidator<UpdateStoreQualificationCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public UpdateStoreQualificationCommandValidator()
    {
        RuleFor(x => x.StoreId).GreaterThan(0);
        RuleFor(x => x.QualificationId).GreaterThan(0);
        RuleFor(x => x.FileUrl).MaximumLength(500).When(x => !string.IsNullOrWhiteSpace(x.FileUrl));
        RuleFor(x => x.DocumentNumber).MaximumLength(100).When(x => !string.IsNullOrWhiteSpace(x.DocumentNumber));
        RuleFor(x => x.SortOrder).GreaterThanOrEqualTo(0).When(x => x.SortOrder.HasValue);
        RuleFor(x => x.ExpiresAt)
            .Must(date => !date.HasValue || date.Value > DateOnly.FromDateTime(DateTime.UtcNow))
            .When(x => x.ExpiresAt.HasValue)
            .WithMessage("证照有效期必须晚于今天");
    }
}
