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

namespace IWS5.Services.Validators;

public class CloneWorkItemRequestValidator : AbstractValidator<CloneWorkItemRequest>
{
    public CloneWorkItemRequestValidator(IWorkItemReferenceRepository workItemReferenceRepository)
    {
        RuleFor(x => x.WorkItemReferenceId)
            .GreaterThan(0).WithMessage("WorkItemReferenceId must be greater than 0.")
            .Must(action => workItemReferenceRepository.AnyAsync(wiReference => wiReference.WorkItemReferenceId == action).Result).WithMessage("WorkItemReferenceId does not exist in the ATWorkItemReference table.");

        RuleFor(x => x.NewWorkItemName)
            .NotNull().WithMessage("NewWorkItemName must not be null.")
            .NotEmpty().WithMessage("NewWorkItemName must not be empty.")
            .MaximumLength(255).WithMessage("NewWorkItemName must not exceed 255 characters.");

        RuleFor(x => x.CloneTrackingRecordMessage)
            .NotNull().WithMessage("CloneTrackingRecordMessage must not be null.")
            .NotEmpty().WithMessage("CloneTrackingRecordMessage must not be empty.")
            .MaximumLength(255).WithMessage("CloneTrackingRecordMessage must not exceed 255 characters.");
    }
}
