using System;
using System.IO;
using System.Linq;

namespace IOB_UT_NEXT
{
    public class utils : IOB_UT_NEXT.baseUtils
    {
        #region Public Properties

        /// <summary>
        /// folder archiviazione dati configurazione (DATA\CONF)
        /// </summary>
        public static string confDir
        {
            get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataConfPath"));
        }

        /// <summary>
        /// folder archiviazione dati storici giornalieri (DATA\DAT)
        /// </summary>
        public static string dataDatDir
        {
            get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataDatPath"));
        }

        /// <summary>
        /// folder archiviazione dati (DATA)
        /// </summary>
        public static string dataDir
        {
            get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("dataPath"));
        }

        /// <summary>
        /// File icona default
        /// </summary>
        public static string defIconFilePath
        {
            get => Path.Combine(utils.resxDir, "SteamWare.ico");
        }

        /// <summary>
        /// File configurazione default x MAIN
        /// </summary>
        public static string mainConfFilePath
        {
            get=> Path.Combine(utils.confDir, utils.CRS("mainConfFile"));
        }

        /// <summary>
        /// folder archiviazione dati configurazione (DATA\CONF)
        /// </summary>
        public static string resxDir
        {
            get => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, CRS("resxPath"));
        }

        #endregion Public Properties

        #region Public Methods

        /// <summary>
        /// file persistenza generale data attuale ANTICIPATA di xx giorni
        /// </summary>
        /// <param name="numDD">num DD di anticipo</param>
        /// <returns></returns>
        public static string prevPersLayerFile(int numDD)
        {
            var dtRif = DateTime.Now.AddDays(-numDD);
            string calcPath = Path.Combine(utils.dataDatDir, $"{dtRif:yyyy}",$"{dtRif:yyyy-MM-dd}.mtc");
            return calcPath;
        }

        /// <summary>
        /// Converte un array di caratteri in una stringa valida (ovvero SOLO numeri/lettere)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string purgedChar2String(char[] input)
        {
            string answ = new string(input.Where(c => char.IsLetter(c) || char.IsDigit(c)).ToArray());
            return answ;
        }

        /// <summary>
        /// Converte una stringa libera in una stringa valida (ovvero SOLO numeri/lettere)
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string purgedChar2String(string input)
        {
            return purgedChar2String(input.ToCharArray());
        }

        #endregion Public Methods
    }
}