using System;
using System.Collections.Generic;
using System.Linq;

namespace isn
{
    public class SourceSettings
    {
        public string ApiKey { get; set; }
        public string Alias { get; set; }

        public string GetClearApiKey()
        {
            return Protector.UnProtect(ApiKey);
        }
        public void SetApiKey(string key)
        {
            ApiKey = Protector.Protect(key);
        }
        
        public static IDataProtector Protector { get; set; } = new DefaultDataProtector();
    }

     

    public class Settings
    {
        public string DataProtectionTitle { get; set; }
        public Dictionary<string, SourceSettings> Sources { get; set; }

        public bool AutoUpdateApiKey { get; set; } = false;

        private string defSourceKey;
        
        /// <summary>
        /// Default source by its alias
        /// </summary>
        /// <value></value>
        public string DefaultSourceKey
        {
            get => defSourceKey;
            set
            {
                if (!Sources.ContainsKey(value))
                {
                    Sources[value]=new SourceSettings
                    {
                        Alias = defSourceKey
                    };
                }
                defSourceKey = value;
            }
        }
    }
}
