using System;
using System.Collections.Generic;

namespace InABox.Configuration
{
    
    public interface IConfiguration<T>
    {
        public string[] Sections();

        T Load(bool useCache = true);
        Dictionary<string, T> LoadAll(IEnumerable<string>? sections = null);

        void Save(T obj);
        /// <summary>
        /// Save all <paramref name="objs"/> to the configuration.
        /// </summary>
        /// <remarks>
        /// This does not do a complete replace; that is, it only changes the configurations with the keys of <paramref name="objs"/>, 
        /// as if <see cref="Save(T)"/> was called for each element in <paramref name="objs"/>
        /// </remarks>
        /// <param name="objs"></param>
        void SaveAll(Dictionary<string, T> objs, bool reset = false);

        void Delete(Action<Exception?>? callback = null);
    }

    public abstract class Configuration<T> : IConfiguration<T>
    {
        public Configuration(string section = "")
        {
            Section = section;
        }

        public string Section { get; }

        public abstract string[] Sections();

        public abstract Dictionary<string, T> LoadAll(IEnumerable<string>? sections = null);

        public abstract T Load(bool useCache = true);

        public abstract void Save(T obj);
        public abstract void SaveAll(Dictionary<string, T> objs, bool reset = false);

        public abstract void Delete(Action<Exception?>? callback);
    }

    public interface IConfigurationSettings
    {
    }
    
    public delegate T LoadSettings<T>(object sender) where T : IConfigurationSettings;
    
    public delegate void SaveSettings<T>(object sender, T properties) where T : IConfigurationSettings;


}