using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace EasyDevCore.Configuration
{
    /// <summary>
    /// 
    /// </summary>
    public interface IEasyConfigOptions
    {
        /// <summary>
        /// Gets or sets the type of the configuration.
        /// </summary>
        /// <value>
        /// The type of the configuration.
        /// </value>
        EasyConfigFileType ConfigType { get; }
        /// <summary>
        /// Gets or sets the encrypt password.
        /// </summary>
        /// <value>
        /// The encrypt password.
        /// </value>
        string EncryptPassword { get; }
        /// <summary>
        /// Gets the automatic save delay.
        /// </summary>
        /// <value>
        /// The automatic save delay.
        /// </value>
        int AutoSaveDelay { get; }
        /// <summary>
        /// Gets a value indicating whether [automatic save].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [automatic save]; otherwise, <c>false</c>.
        /// </value>
        bool AutoSave { get; }
        /// <summary>
        /// Gets or sets the name of the file.
        /// </summary>
        /// <value>
        /// The name of the file.
        /// </value>
        string FileName { get; }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <seealso cref="EasyDevCore.Configuration.IEasyConfigOptions" />
    /// <seealso cref="System.ComponentModel.INotifyPropertyChanged" />
    /// <seealso cref="INotifyPropertyChanged" />
    public class EasyConfigOptions : IEasyConfigOptions, INotifyPropertyChanged
    {
        /// <summary>
        /// Gets or sets the type of the configuration.
        /// </summary>
        /// <value>
        /// The type of the configuration.
        /// </value>
        public EasyConfigFileType ConfigType { get; internal set; } = EasyConfigFileType.Auto;
        /// <summary>
        /// Gets or sets the encrypt password.
        /// </summary>
        /// <value>
        /// The encrypt password.
        /// </value>
        public string EncryptPassword { get; set; }
        private int _AutoSaveDelay = 10;
        /// <summary>
        /// Gets the automatic save delay.
        /// </summary>
        /// <value>
        /// The automatic save delay.
        /// </value>
        public int AutoSaveDelay
        {
            get => _AutoSaveDelay;
            set
            {
                _AutoSaveDelay = value;
                NotifyPropertyChanged();
            }
        }
        private bool _AutoSave = false;
        /// <summary>
        /// Gets a value indicating whether [automatic save].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [automatic save]; otherwise, <c>false</c>.
        /// </value>
        public bool AutoSave
        {
            get => _AutoSave;
            set
            {
                _AutoSave = value;
                NotifyPropertyChanged();
            }
        }
        /// <summary>
        /// Gets or sets the name of the file.
        /// </summary>
        /// <value>
        /// The name of the file.
        /// </value>
        public string FileName { get; set; }
        /// <summary>
        /// Occurs when a property value changes.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        // This method is called by the Set accessor of each property.  
        // The CallerMemberName attribute that is applied to the optional propertyName  
        // parameter causes the property name of the caller to be substituted as an argument.  
        private void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

    }
}
