using FluentValidation;
using Meezi.API.Models.Printing;

namespace Meezi.API.Validators;

public class PatchBranchPrintSettingsRequestValidator : AbstractValidator<PatchBranchPrintSettingsRequest>
{
    public PatchBranchPrintSettingsRequestValidator()
    {
        RuleFor(x => x.ReceiptPrinterPort)
            .InclusiveBetween(1, 65535)
            .When(x => x.ReceiptPrinterPort.HasValue);
        RuleFor(x => x.KitchenPrinterPort)
            .InclusiveBetween(1, 65535)
            .When(x => x.KitchenPrinterPort.HasValue);
        RuleFor(x => x.PaperWidthMm)
            .Must(w => w is null or 58 or 80)
            .WithMessage("Paper width must be 58 or 80 mm.");
        RuleFor(x => x.ReceiptHeader).MaximumLength(500).When(x => x.ReceiptHeader is not null);
        RuleFor(x => x.ReceiptFooter).MaximumLength(500).When(x => x.ReceiptFooter is not null);
        RuleFor(x => x.WifiPassword).MaximumLength(100).When(x => x.WifiPassword is not null);
        RuleFor(x => x.PosDevicePort)
            .InclusiveBetween(1, 65535)
            .When(x => x.PosDevicePort.HasValue);
    }
}

public class PosPaymentRequestValidator : AbstractValidator<PosPaymentRequest>
{
    public PosPaymentRequestValidator()
    {
        RuleFor(x => x.OrderId).NotEmpty().MaximumLength(64);
        RuleFor(x => x.Amount).GreaterThan(0);
    }
}

public class TestPrintRequestValidator : AbstractValidator<TestPrintRequest>
{
    public TestPrintRequestValidator()
    {
        RuleFor(x => x.PrinterIp).NotEmpty().MaximumLength(45);
        RuleFor(x => x.Port).InclusiveBetween(1, 65535);
    }
}
