using FluentValidation.Results;

namespace PARR.API.Contracts.V1.Responses.Base
{
    public class Response<T> : BaseResponse
    {
        public Response(T response, bool isSuccess) : base(isSuccess)
        {
            Data = response;
        }

        public Response(T response, bool isSuccess, List<ErrorModel> errors) : base(isSuccess, errors)
        {
            Data = response;
        }

        public Response(T response, bool isSuccess, List<ErrorModel> errors, string message) : base(isSuccess, errors, message)
        {
            Data = response;
        }

        public T? Data { get; private set; }
    }


    public class Response : Response<object?>
    {
        /// <summary>
        /// Респонс для валидации от FluentValidator
        /// </summary>
        /// <param name="validationErrors">ResultValidate.Errors</param>
        public Response(List<ValidationFailure> validationErrors) : base(null, false)
        {
            var errors = new List<ErrorModel>();
            foreach (var error in validationErrors)
            {
                errors.Add(new ErrorModel
                {
                    FieldName = error.PropertyName,
                    Message = error.ErrorMessage
                });
            }

            Errors = errors;
        }

        /// <summary>
        /// Респонс когда не нужно передавать объект
        /// </summary>
        /// <param name="isSuccess"></param>
        /// <param name="errors"></param>
        public Response(bool isSuccess, List<ErrorModel> errors) : base(null, isSuccess, errors)
        {

        }
    }
}
