using IOB_UT_NEXT;
using IOB_WIN_BECKHOFF.Iob;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IOB_WIN_BECKHOFF
{
    public class AdapterFormNext: IOB_WIN_FORM.AdapterForm
    {

        /// <summary>
        /// Avvio MainForm
        /// </summary>
        /// <param name="codIOB"></param>
        public AdapterFormNext(string codIOB): base(codIOB)
        {
        }
        /// <summary>
        /// carica IOB richiesto
        /// </summary>
        protected override void loadIobType()
        {
            if (IOBConfFull != null)
            {
                switch (tipoScelto)
                {
                    case tipoAdapter.BECKHOFF:
                    case tipoAdapter.BECKHOFF_CPA:
                        iobObj = new IobBeckhoff.BeckhoffCpa(this, IOBConfFull);
                        btnStart.Enabled = true;
                        break;

                    case tipoAdapter.SIMULA:
                    case tipoAdapter.ND:
                    default:
                        iobObj = new IOB_WIN_FORM.Iob.Simula(this, IOBConfFull);
                        btnStart.Enabled = false;
                        break;
                }
                lblCncText = $"CNC: {IOBConfFull.General.IobType} [{IOBConfFull.Device.Connect.IpAddr}:{IOBConfFull.Device.Connect.Port}]";
                lblSrvUrlText = $"SRV: {IOBConfFull.MapoMesConf.IpAddr} | URL: {IOBConfFull.MapoMesConf.ApiUrl("")}";

                // aggancio evento refresh
                iobObj.eh_refreshed += IobObj_eh_refreshed;

                // carico i default values su interfaccia
                setDefaults();

                displayTaskAndLog($"Caricata conf per adapter {tipoScelto}");
            }
        }
    }
}
