namespace IOB_UT_NEXT
{
    public class BitConditionCheck
    {
        #region Public Constructors

        /// <summary>
        /// Inizializza un oggetto da usare per testing bit condition
        /// </summary>
        /// <param name="keyName">Nome della chiave registrata</param>
        /// <param name="rawConf">Configurazione nel formato BaseAddr.BitNum=ValOk</param>
        public BitConditionCheck(string keyName, string rawConf)
        {
            Logging.Instance.Info($"Init BitConditionCheck | {keyName} | {rawConf}");
            KeyName = keyName;
            RawVal = rawConf;
            string sVal = "";
            int valDecoded = 0;
            // check preliminare
            if (rawConf.Contains(".") && rawConf.Contains("="))
            {
                // splitto per "="...
                var splitCond = rawConf.Split('=');
                sVal = splitCond[1];
                int.TryParse(sVal, out valDecoded);
                ValOk = valDecoded;
                // il restante splitto per "."
                var splitMem = splitCond[0].Split('.');
                // BaseAddr
                sVal = splitMem[0];
                int.TryParse(sVal, out valDecoded);
                BaseAddr = valDecoded;
                // BitNum
                sVal = splitMem[1];
                int.TryParse(sVal, out valDecoded);
                BitNum = valDecoded;
            }
        }

        /// <summary>
        /// Inizializza un oggetto fake/empty
        /// </summary>
        public BitConditionCheck()
        {
            Logging.Instance.Info("Init empty BitConditionCheck");
        }

        /// <summary>
        /// Inizializza un oggetto solo per key
        /// </summary>
        /// <param name="keyName">Nome della chiave registrata</param>
        public BitConditionCheck(string keyName)
        {
            Logging.Instance.Info($"Init BitConditionCheck | {keyName}");
            KeyName = keyName;
        }

        #endregion Public Constructors

        #region Public Properties

        /// <summary>
        /// Indirizzo base x memoria da testare come bit condition
        /// </summary>
        public int BaseAddr { get; set; } = 0;

        /// <summary>
        /// Numero bit da impiegare
        /// </summary>
        public int BitNum { get; set; } = 0;

        /// <summary>
        /// Valore chiave
        /// </summary>
        public string KeyName { get; set; } = "";

        /// <summary>
        /// Valore raw decodificato
        /// </summary>
        public string RawVal { get; set; } = "";

        /// <summary>
        /// Valore target che porta a condizione OK = true
        /// </summary>
        public int ValOk { get; set; } = 0;

        #endregion Public Properties
    }
}