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

namespace RateTableGUI
{
    interface IRateTable
    {
        bool Connect(string portName, string baudRate, string dataBits, string stopBits, string parity);
        bool Connect(System.Net.IPAddress ip, int port);
        void Disconnect();
        void Init();
        void SetAxis1(int deg);
        void SetAxis1(int deg, int vel);
        void SetAxis2(int deg);
        void SetAxis2(int deg, int vel);
        void ProvidesCommands(bool rateTable, bool climaChamber, bool axisInner, bool axisInnerRotate, int axisInnerPos, int axisInnerVel, bool axisOuter, bool axisOuterRotate, int axisOuterPos, int axisOuterVel);
        bool Stop();
        bool Run();
        void ManualUpdate();
        void SendCommandProvider(string cmd);
        string ReadCommandProvider();

        float GetInnerZeroPos();
        float GetInnerVel();
        int GetInnerStatus();
        float GetInnerRefPos();
        float GetInnerActPoc();
        float GetInnerActAcc();

        float GetOuterZeroPos();
        float GetOuterVel();
        int GetOuterStatus();
        float GetOuterRefPos();
        float GetOuterActPoc();
        float GetOuterActAcc();

        string ChamberName { get; }
    }

    public static class RateTableError
    {
        private static State_e State;
        private static List<string> Fulltext = new List<string>();
        private static List<string> ShortText = new List<string>();
        private static List<string> Source = new List<string>();

        public enum State_e
        {
            Normal,
            Critical
        }

        public static bool isActive { get; private set; }

        public static void Add(string source, string shortText, string fullText, bool iscritical = false)
        {
            isActive = true;
            Fulltext.Add(fullText);
            ShortText.Add(shortText);
            Source.Add(source);

            if (iscritical)
                State = State_e.Critical;
            else
                State = State_e.Normal;
        }

        public static State_e GetMsg(out List<string[]> errors)
        {
            isActive = false;
            errors = new List<string[]>();
            for (int i = 0; i < Fulltext.Count; i++)
                errors.Add(new string[]
                {
                    string.Format("Rotaryr table controller: Source[{0}] -> ShortText = {1}", Source[i], ShortText[i]),
                    string.Format("Rotaryr table controller: Source[{0}] -> ShortText = {1} -> FullText = {2}", Source[i], ShortText[i], Fulltext[i])
                });

            Source.Clear();
            ShortText.Clear();
            Fulltext.Clear();

            return State;
        }
    }
}
