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

namespace TakeoutSaaS.Application.App.Stores.Validators;

/// <summary>
/// 创建门店命令验证器。
/// </summary>
public sealed class CreateStoreCommandValidator : AbstractValidator<CreateStoreCommand>
{
    /// <summary>
    /// 初始化验证规则。
    /// </summary>
    public CreateStoreCommandValidator()
    {
        // 1. 校验核心字段
        RuleFor(command => command.Name).NotEmpty().MaximumLength(128);
        RuleFor(command => command.ContactPhone).NotEmpty().MaximumLength(32);
        RuleFor(command => command.ManagerName).NotEmpty().MaximumLength(64);
        RuleFor(command => command.Address).NotEmpty().MaximumLength(256);

        // 2. 校验可选字段
        RuleFor(command => command.CoverImage).MaximumLength(500);
        RuleFor(command => command.BusinessStatus).IsInEnum().When(command => command.BusinessStatus.HasValue);

        // 3. 校验服务方式列表
        RuleForEach(command => command.ServiceTypes).IsInEnum();
    }
}

