using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using OliviaAddInPro.Helper;
using OliviaAddInPro.Model;
using OliviaAddInPro.Services;

namespace OliviaAddInPro
{
    class PaneConfigViewModel : PanelViewModelBase
    {
        private OliviaConf conf=null;
        public PaneConfigViewModel()
        {                
            OnRefres();
        }

        public bool hay_cambios = false;
  

        public override string DisplayName
        {
            get { return Resource1.String_ConfigGeneralView; }
        }

        public OliviaConf Configuracion
        {
            get { return conf; }
            set 
            { 
                base.SetProperty(ref conf, value, () => conf);
                base.NotifyPropertyChanged("Configuracion");
                //ConfiguracioProperty.Update();
             }
            
    }

        public void OnGuardar()
        {
            Respuesta<bool> resp = ConfigServ.Serv.Guardar(Configuracion);
            if (!resp.Value)
                HelperGlobal.ponMsg(resp.Error.First());
            else            
                HelperGlobal.ponMsg("Se ha guardado la configuración");
            hay_cambios = false;
        }

        public void OnRefres()
        {
            Configuracion = ConfigServ.Serv.Leer();
            hay_cambios = false;
        }
    }

}
