﻿namespace Dike.Web.Configuration
{
    using Microsoft.AspNetCore.Mvc.ApplicationModels;
    using System;

    /// <summary>
    /// Use this class to create controllers for application services from an assembly.
    /// </summary>
    /// <seealso cref="Dike.Web.Configuration.IControllerAssemblySettingBuilder" />
    public class ControllerAssemblySettingBuilder
        : IControllerAssemblySettingBuilder
    {
        #region Fields

        private readonly ControllerAssemblySetting _setting;

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="ControllerAssemblySettingBuilder"/> class.
        /// </summary>
        /// <param name="setting">The setting.</param>
        public ControllerAssemblySettingBuilder(ControllerAssemblySetting setting)
        {
            _setting = setting;
        }

        #endregion Constructors

        #region Methods

        /// <summary>
        /// Adds a configuration action to the <see cref="ControllerAssemblySetting.TypePredicate"/> and returns a reference the his self.
        /// </summary>
        /// <param name="configurer">The configuration action.</param>
        /// <returns>A reference to his self.</returns>
        public ControllerAssemblySettingBuilder ConfigureControllerModel(Action<ControllerModel> configurer)
        {
            _setting.ControllerModelConfigurer = configurer;
            return this;
        }

        /// <summary>
        /// Adds the predicate to the <see cref="ControllerAssemblySetting.TypePredicate"/> and returns a reference the his self.
        /// </summary>
        /// <param name="predicate">The predicate to add.</param>
        /// <returns>A reference to his self.</returns>
        public ControllerAssemblySettingBuilder Where(Func<Type, bool> predicate)
        {
            _setting.TypePredicate = predicate;
            return this;
        }

        #endregion Methods
    }
}