using System;

namespace Wayne.Lib
{
    /// <summary>
    /// Exception thrown by the service container.
    /// </summary>
    public class ServiceContainerException : ApplicationException
    {
        /// <summary>
        /// Type of service that this exception is about.
        /// </summary>
        public Type ServiceType { get; private set; }

        internal ServiceContainerException(Type serviceType, string message)
            : base(message)
        {
            ServiceType = serviceType;
        }

        /// <summary>
        /// Creates a new ServiceContainerException saying that a service was not found.
        /// </summary>
        /// <param name="type">Type of the service not found.</param>
        /// <returns>New ServiceContainerException.</returns>
        public static ServiceContainerException CreateNotFoundException(Type type)
        {
            return new ServiceContainerException(type, string.Format("Service {0} not found!", type));
        }

        /// <summary>
        /// Creates a new ServiceContainerException saying that a service's dependency was not found in the container.
        /// </summary>
        /// <param name="typeToCreate">Type of service that is being created.</param>
        /// <param name="dependency">Type of dependency not found.</param>
        /// <returns>New ServiceContainerException.</returns>
        public static ServiceContainerException CreateDependencyNotFound(Type typeToCreate, Type dependency)
        {
            return new ServiceContainerException(typeToCreate, string.Format("Type {0} could not be created because dependency {1} could not be found in the container!", typeToCreate, dependency));
        }
    }
}