using FluentValidation;
using IWS5.Core.Models.Request;
using IWS5.DatabaseAccess.Interfaces;

namespace IWS5.Services.Validators;

public class ListProcessAllowedTemplatesRequestValidator : AbstractValidator<ListProcessAllowedTemplatesRequest>
{
    public ListProcessAllowedTemplatesRequestValidator(IProcessRepository processRepository)
    {
        RuleFor(request => request.ProcessId)
            .NotEqual(0).WithMessage("ProcessId must be greater than 0")
            .Must(processId =>
            {
                var processExists =  processRepository.AnyAsync(process => process.ProcessId == processId).Result;
                return processExists;
            }).WithMessage(process => $"Process with id {process.ProcessId} was not found");
    }
}