using System;

namespace Valg.EVA.Skanning.Configuration
{
    public class ReadSoftIniKey
    {
        
        public static readonly string ScanTypeKey = "ReadSoft.INI.EHLOCAL.Scanner.ScanType";
        
        public string FileName { get; set; }
        public string Section { get; set; }
        public string IniKey { get; set; }
        public string IniValue { get; set; }
        
        public ReadSoftIniKey(string iniSetting)
        {
            var keySplitted = iniSetting.Split('.');
            FileName = keySplitted[2];
            Section = keySplitted[3];
            IniKey = keySplitted[4];

            GetIniValue();
        }

        public void SetValue(string value)
        {
            var data = ReadSoftIniFileParser.ParseFile(FileName);
            data[Section][IniKey] = value;
            ReadSoftIniFileParser.WriteFile(FileName, data);
        }


        private void GetIniValue()
        {
            var data = ReadSoftIniFileParser.ParseFile(FileName);
            IniValue = data[Section][IniKey];
        }
    }

    public class ScanCardIniKey : ReadSoftIniKey
    {
        public ScanCardIniKey() : base("ReadSoft.INI.EHLOCAL.Scanner.ScanCard")
        {}

        public bool IsEmulate => string.Compare(IniValue, "Emulate", StringComparison.InvariantCultureIgnoreCase) == 0;
    }
}

