using System;
using System.IO;
using System.Text;
using IniParser;
using IniParser.Model;

namespace Valg.EVA.Skanning.Configuration
{
    public class ReadSoftIniFileParser
    {
        private static readonly string publicUsersPath = Path.GetDirectoryName(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments));

        public static IniData ParseFile(string fileName)
        {
            var iniFileName = GetIniFileName(fileName);
            var parser = new FileIniDataParser();
            var data = parser.ReadFile(iniFileName);
            return data;
        }

        public static void WriteFile(string fileName, IniData data)
        {
            var iniFileName = GetIniFileName(fileName);
            var parser = new FileIniDataParser();            
            parser.WriteFile(iniFileName, data, Encoding.Default); 
        }

        private static string GetIniFileName(string fileName)
        {
            return Path.Combine(publicUsersPath, $"ReadSoft\\FORMS\\{fileName}.ini");
        }
    }
}
