using Informes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace Controladora
{
    public class ControladoraInformes : Singleton<ControladoraInformes>
    {
        const string configpath = "settings.json";

        public void GuardarConfig(ConfigEmail config)
        {
            try
            {
                string json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
                File.WriteAllText(configpath, json);

            }
            catch (IOException ex) { throw; }
        }

        public ConfigEmail RecuperarConfig()
        {
            try
            {
                if (!File.Exists(configpath))
                {
                    string json = JsonSerializer.Serialize(new ConfigEmail { EmailAddr = "", EmailPass = "", EmailTarget = new List<String>() }, new JsonSerializerOptions { WriteIndented = true });
                    File.WriteAllText(configpath, json);
                }
            }
            catch (IOException ex) { throw; }

            string jsonString = File.ReadAllText(configpath);
            return JsonSerializer.Deserialize<ConfigEmail>(jsonString);
        }
    }
}
