using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using NetMonitorTray.Properties;
using BlubbFish.Utils;
using NetMonitorUtils;

namespace NetMonitorTray.Models {
  public class Window : OwnModel<Window> {
    private InIReader networkfile;
    private InIReader vpnfile;
    private InIReader settingsfile;
    private NetworkSetter networksetter;
    private Window() {
      this.init();
    }

    override protected void init() {
      this.networkfile = InIReader.getInstance("network.ini");
      this.vpnfile = InIReader.getInstance("vpn.ini");
      this.settingsfile = InIReader.getInstance("config.ini");
      this.networksetter = new NetworkSetter("network.ini", "config.ini");
    }

    /// <summary>
    /// Listet alle Netzwerke auf
    /// </summary>
    public List<string> Networks {
      get { return this.networkfile.getSections(); }
    }

    public List<string> Vpns {
      get { return this.vpnfile.getSections(); }
    }

    

    /// <summary>
    /// Fügt ein neues Netzwerk hinzu
    /// </summary>
    /// <param name="name">Netzwerkid</param>
    /// <returns>true if added, false if error</returns>
    public bool addNetwork(string name) {
      if(this.networkfile.addSection(name)) {
        this.update();
        return true;
      }
      return false;
    }

    /// <summary>
    /// Löscht ein Netzwerk
    /// </summary>
    /// <param name="name">Netzwerkid</param>
    /// <returns>true if deleted, false if error</returns>
    public bool removeNetwork(string name) {
      if(this.networkfile.removeSection(name)) {
        this.update();
        return true;
      }
      return false;
    }

    internal string getVpnProperty(string vpn, string property) {
      return this.vpnfile.getValue(vpn, property);
    }

    public string getNetworkProperty(string network, string property) {
      return this.networkfile.getValue(network, property);
    }

    public string getSettingsProperty(string setting, string property) {
      return this.settingsfile.getValue(setting, property);
    }

    public List<string> getNetworkAdapters() {
      return this.networksetter.getAdapters();
    }
  }
}