﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BookReviews.Infrastructure.Exceptions
{
    public class ModelStateInvalidException : Exception
    {
        public ModelStateInvalidException(string reason = null)
            : base()
        {
            Reason = FormatReason(reason);
        }

        public ModelStateInvalidException(string modelStateErrorKey, string reason = null)
            : base()
        {
            Reason = FormatReason(reason);
            ModelStateErrorKey = modelStateErrorKey;
        }

        public ModelStateInvalidException(string message, string modelStateErrorKey, string reason = null)
            : base(message)
        {
            Reason = FormatReason(reason);
            ModelStateErrorKey = modelStateErrorKey;
        }

        public ModelStateInvalidException(string message, Exception innerException, string modelStateErrorKey, string reason = null)
            : base(message, innerException)
        {
            Reason = FormatReason(reason);
            ModelStateErrorKey = modelStateErrorKey;
        }

        public string ModelStateErrorKey { get; private set; }

        public string Reason { get; private set; }

        private string FormatReason(string reasonMessage)
        {
            return reasonMessage == null ? string.Empty : reasonMessage;
        }
    }
}
