﻿// MIT License. Copyright (c) 2016 Maxim Kuzmin. Contacts: https://github.com/maxim-kuzmin

// Author: Maxim Kuzmin

using Makc2017.Core.Caching;
using Makc2017.Core.Configuration;

namespace Makc2017.Modules.DummyManyToMany.Caching
{
    /// <summary>
    /// Модули. Модуль "DummyManyToMany". Кэширование. Конфигурация.
    /// </summary>
    internal class ModuleDummyManyToManyCachingConfig : ICoreCachingClientConfig
    {
        #region Properties

        /// <summary>
        /// Окончание срока действия кэша в секундах.
        /// </summary>
        public CoreConfigurationParameter<int> CacheExpiryInSeconds { get; set; }

        /// <summary>
        /// Признак включения кэширования.
        /// </summary>
        public CoreConfigurationParameter<bool> IsCachingEnabled { get; private set; }

        /// <summary>
        /// Префикс ключа кэша.
        /// </summary>
        public CoreConfigurationParameter<string> CacheKeyPrefix { get; private set; }

        #endregion Properties

        #region Constructors

        /// <summary>
        /// Конструктор настроек модуля.
        /// </summary>
        public ModuleDummyManyToManyCachingConfig()
        {
            CacheExpiryInSeconds = new CoreConfigurationParameter<int>(
                "Module:DummyManyToMany:Caching:CacheExpiryInSeconds",
                0,
                str => int.Parse(str)
                );

            IsCachingEnabled = new CoreConfigurationParameter<bool>(
                "Module:DummyManyToMany:Caching:IsCachingEnabled", 
                true, 
                str => bool.Parse(str)
                );

            CacheKeyPrefix = new CoreConfigurationParameter<string>(
                "Module:DummyManyToMany:Caching:CacheKeyPrefix",
                "Module:DummyManyToMany:",
                str => str
                );
        }

        #endregion Constructors

        #region Public methods

        /// <summary>
        /// Инициализировать.
        /// </summary>        
        /// <param name="provider">Поставщик конфигурации.</param>
        public void Init(ICoreConfigurationProvider provider)
        {
            ModuleDummyManyToManyCachingSerialization.Init();

            CacheExpiryInSeconds.Init(provider);
            IsCachingEnabled.Init(provider);
            CacheKeyPrefix.Init(provider);
        }

        #endregion Public methods
    }
}