// EN: Validators for Attendance and Leave Request commands.
// VI: Validators cho cac commands Cham cong va Nghi phep.

using FluentValidation;
using MerchantService.API.Application.Commands.Attendance;
using MerchantService.API.Application.Commands.LeaveRequests;
using MerchantService.API.Application.Commands.Shops;

namespace MerchantService.API.Application.Validations;

/// <summary>
/// EN: Validator for CheckInCommand.
/// VI: Validator cho CheckInCommand.
/// </summary>
public class CheckInCommandValidator : AbstractValidator<CheckInCommand>
{
    public CheckInCommandValidator()
    {
        RuleFor(x => x.StaffId)
            .NotEmpty()
            .WithMessage("Staff ID is required / Staff ID la bat buoc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID la bat buoc");
    }
}

/// <summary>
/// EN: Validator for CheckOutCommand.
/// VI: Validator cho CheckOutCommand.
/// </summary>
public class CheckOutCommandValidator : AbstractValidator<CheckOutCommand>
{
    public CheckOutCommandValidator()
    {
        RuleFor(x => x.StaffId)
            .NotEmpty()
            .WithMessage("Staff ID is required / Staff ID la bat buoc");
    }
}

/// <summary>
/// EN: Validator for CreateLeaveRequestCommand.
/// VI: Validator cho CreateLeaveRequestCommand.
/// </summary>
public class CreateLeaveRequestCommandValidator : AbstractValidator<CreateLeaveRequestCommand>
{
    private static readonly string[] ValidLeaveTypes = ["Annual", "Sick", "Personal", "Maternity", "Paternity", "Unpaid"];

    public CreateLeaveRequestCommandValidator()
    {
        RuleFor(x => x.StaffId)
            .NotEmpty()
            .WithMessage("Staff ID is required / Staff ID la bat buoc");

        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID la bat buoc");

        RuleFor(x => x.LeaveType)
            .NotEmpty()
            .WithMessage("Leave type is required / Loai nghi phep la bat buoc")
            .MaximumLength(50)
            .WithMessage("Leave type must not exceed 50 characters / Loai nghi phep khong vuot qua 50 ky tu");

        RuleFor(x => x.StartDate)
            .NotEmpty()
            .WithMessage("Start date is required / Ngay bat dau la bat buoc");

        RuleFor(x => x.EndDate)
            .NotEmpty()
            .WithMessage("End date is required / Ngay ket thuc la bat buoc")
            .GreaterThanOrEqualTo(x => x.StartDate)
            .WithMessage("End date must be on or after start date / Ngay ket thuc phai bang hoac sau ngay bat dau");

        RuleFor(x => x.Reason)
            .MaximumLength(1000)
            .WithMessage("Reason must not exceed 1000 characters / Ly do khong vuot qua 1000 ky tu")
            .When(x => x.Reason != null);
    }
}

/// <summary>
/// EN: Validator for ApproveLeaveRequestCommand.
/// VI: Validator cho ApproveLeaveRequestCommand.
/// </summary>
public class ApproveLeaveRequestCommandValidator : AbstractValidator<ApproveLeaveRequestCommand>
{
    public ApproveLeaveRequestCommandValidator()
    {
        RuleFor(x => x.LeaveRequestId)
            .NotEmpty()
            .WithMessage("Leave request ID is required / ID yeu cau nghi phep la bat buoc");

        RuleFor(x => x.ApprovedBy)
            .NotEmpty()
            .WithMessage("Approver ID is required / ID nguoi duyet la bat buoc");
    }
}

/// <summary>
/// EN: Validator for RejectLeaveRequestCommand.
/// VI: Validator cho RejectLeaveRequestCommand.
/// </summary>
public class RejectLeaveRequestCommandValidator : AbstractValidator<RejectLeaveRequestCommand>
{
    public RejectLeaveRequestCommandValidator()
    {
        RuleFor(x => x.LeaveRequestId)
            .NotEmpty()
            .WithMessage("Leave request ID is required / ID yeu cau nghi phep la bat buoc");

        RuleFor(x => x.RejectedBy)
            .NotEmpty()
            .WithMessage("Rejector ID is required / ID nguoi tu choi la bat buoc");

        RuleFor(x => x.Reason)
            .MaximumLength(1000)
            .WithMessage("Reason must not exceed 1000 characters / Ly do khong vuot qua 1000 ky tu")
            .When(x => x.Reason != null);
    }
}

/// <summary>
/// EN: Validator for UpdateShopCommand.
/// VI: Validator cho UpdateShopCommand.
/// </summary>
public class UpdateShopCommandValidator : AbstractValidator<UpdateShopCommand>
{
    public UpdateShopCommandValidator()
    {
        RuleFor(x => x.ShopId)
            .NotEmpty()
            .WithMessage("Shop ID is required / Shop ID la bat buoc");

        RuleFor(x => x.Name)
            .NotEmpty()
            .WithMessage("Shop name is required / Ten shop la bat buoc")
            .MaximumLength(100)
            .WithMessage("Shop name must not exceed 100 characters / Ten shop khong vuot qua 100 ky tu");

        RuleFor(x => x.Description)
            .MaximumLength(2000)
            .WithMessage("Description must not exceed 2000 characters / Mo ta khong vuot qua 2000 ky tu")
            .When(x => x.Description != null);

        RuleFor(x => x.Phone)
            .MaximumLength(20)
            .WithMessage("Phone must not exceed 20 characters / So dien thoai khong vuot qua 20 ky tu")
            .When(x => x.Phone != null);

        RuleFor(x => x.Email)
            .EmailAddress()
            .WithMessage("Invalid email format / Dinh dang email khong hop le")
            .When(x => !string.IsNullOrEmpty(x.Email));

        RuleFor(x => x.Website)
            .MaximumLength(200)
            .WithMessage("Website must not exceed 200 characters / Website khong vuot qua 200 ky tu")
            .When(x => x.Website != null);

        RuleFor(x => x.LogoUrl)
            .MaximumLength(2048)
            .WithMessage("Logo URL must not exceed 2048 characters / URL logo khong vuot qua 2048 ky tu")
            .When(x => x.LogoUrl != null);

        RuleFor(x => x.CoverImageUrl)
            .MaximumLength(2048)
            .WithMessage("Cover image URL must not exceed 2048 characters / URL anh bia khong vuot qua 2048 ky tu")
            .When(x => x.CoverImageUrl != null);
    }
}
