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

namespace FSI.BT.IR.Plc.Settings.Log.Settings
{
    public class Context
    {
        public interface ISettings : INotifyPropertyChanged
        {
            /// <summary>
            /// Daten von appsettings.json
            /// </summary>
            public Settings Settings { get; set; }

            /// <summary>
            /// Daten von config.json
            /// </summary>
            public Cfg Cfg { get; set; }
        }

        /// <summary>
        /// Daten von appsettings.json
        /// </summary>
        public record Settings
        {
            /// <summary>
            /// Versions-Informationen
            /// </summary>
            public Version Version { get; set; }

            /// <summary>
            /// Build-Informationen
            /// </summary>
            public Build Build { get; set; }

            /// <summary>
            /// Logging-Einstellungen
            /// </summary>
            public Logging Logging { get; set; }
        }

        /// <summary>
        /// Versions-Informationen
        /// </summary>
        public record Version
        {
            /// <summary>
            /// Haupt-Versionsnummer
            /// </summary>
            public uint Major { get; set; } = 0;

            /// <summary>
            /// Unter-Versionsnummer
            /// </summary>
            public uint Minor { get; set; } = 0;

            /// <summary>
            /// Patch/Hotfix
            /// </summary>
            public uint Patch { get; set; } = 0;

            /// <summary>
            /// optinoale Versionsinformationen
            /// </summary>
            public string? Optional { get; set; }

            /// <summary>
            /// gibt die Versions-Nummer zurück
            /// </summary>
            /// <returns>Versionsnummer</returns>
            public override string ToString()
            {
                return Major.ToString() + "." + Minor.ToString() + "." + Patch.ToString() + ((Optional == string.Empty || Optional == null) ? "" : "-" + Optional);
            }
        }

        /// <summary>
        /// Build-Informationen
        /// </summary>
        public record Build
        {
            /// <summary>
            /// Ersteller
            /// </summary>
            public string Creator { get; set; }

            /// <summary>
            /// Organisation
            /// </summary>
            public string Organization { get; set; }

            /// <summary>
            /// Erstellungsjahr
            /// </summary>
            public int CreationYear { get; set; }

            /// <summary>
            /// Beschreibung
            /// </summary>
            public string Description { get; set; }
        }

        public class Logging
        {
            public Loglevel LogLevel { get; set; }
        }

        /// <summary>
        /// Logging-Einstellungen
        /// </summary>
        public class Loglevel
        {
            public string Default { get; set; }

            [ConfigurationKeyName("Microsoft.Hosting.Lifetime")]
            public string MicrosoftHostingLifetime { get; set; }
        }

        /// <summary>
        /// Daten von config.json
        /// </summary>
        public record Cfg
        {
            /// <summary>
            /// Update Intevall in ms
            /// </summary>
            public int UpdateInterval { get; set; }

            /// <summary>
            /// Clean intevall in days
            /// </summary>
            public int CleanInterval {  get; set; }
        }
    }
}
