// EN: Validator for GetRevenueAnalyticsQuery.
// VI: Validator cho GetRevenueAnalyticsQuery.

using FluentValidation;
using OrderService.API.Application.Queries.Reports;

namespace OrderService.API.Application.Validations;

/// <summary>
/// EN: Validator for GetRevenueAnalyticsQuery — validates date range, period, and shop ID.
/// VI: Validator cho GetRevenueAnalyticsQuery — kiem tra khoang ngay, ky, va shop ID.
/// </summary>
public class GetRevenueAnalyticsQueryValidator : AbstractValidator<GetRevenueAnalyticsQuery>
{
    private static readonly string[] ValidPeriods = { "daily", "weekly", "monthly" };

    public GetRevenueAnalyticsQueryValidator()
    {
        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("EN: Shop ID is required / VI: Shop ID la bat buoc");

        RuleFor(x => x.StartDate)
            .NotEmpty()
            .WithMessage("EN: Start date is required / VI: Ngay bat dau la bat buoc")
            .LessThan(x => x.EndDate)
            .WithMessage("EN: Start date must be before end date / VI: Ngay bat dau phai truoc ngay ket thuc");

        RuleFor(x => x.EndDate)
            .NotEmpty()
            .WithMessage("EN: End date is required / VI: Ngay ket thuc la bat buoc")
            .Must(d => d <= DateTime.UtcNow.Date.AddDays(1))
            .WithMessage("EN: End date cannot be in the future / VI: Ngày kết thúc không thể trong tương lai");

        RuleFor(x => x.Period)
            .NotEmpty()
            .WithMessage("EN: Period is required / VI: Ky la bat buoc")
            .Must(p => ValidPeriods.Contains(p.ToLowerInvariant()))
            .WithMessage("EN: Period must be 'daily', 'weekly', or 'monthly' / VI: Ky phai la 'daily', 'weekly', hoac 'monthly'");
    }
}
