using System.Text;

namespace Test_ACS
{
    public partial class MainForm
    {
        public class RemoteStatus
        {
            public byte Mode { get; set; } // 0=manual, 1=auto
            public byte RunSt { get; set; } // 0=stop, 1=run, 2=error
            public byte RunStep { get; set; }
            public byte RunStepSeq { get; set; }
            public ushort HWError { get; set; }
            public byte MotorDir { get; set; } // 0=F, 1=B
            public byte MagnetDir { get; set; } // 0=S, 1=L, 2=R
            public byte ChargeSt { get; set; } // 0=off, 1=on
            public byte CartSt { get; set; } // 0=off, 1=on, 2=unknown
            public byte LiftSt { get; set; } // 0=down, 1=up, 2=unknown
            public byte ErrorCode { get; set; }
            public string LastTag { get; set; }

            public override string ToString()
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine($"Mode: {(Mode == 1 ? "Auto" : "Manual")}");
                sb.AppendLine($"RunSt: {(RunSt == 0 ? "Stop" : (RunSt == 1 ? "Run" : "Error"))}");
                if (HWError > 0)
                {
                    sb.Append(" [HW ERR: ");
                    for (int i = 0; i < 16; i++)
                    {
                        if ((HWError & (1 << i)) != 0)
                        {
                            sb.Append($"{(arDev.Narumi.eflag)i},");
                        }
                    }
                    sb.AppendLine("]");
                }
                sb.AppendLine($"Step: {RunStep}, Seq: {RunStepSeq}");
                sb.AppendLine($"Dir: {(MotorDir == 1 ? "B" : "F")}, Mag: {(MagnetDir == 1 ? "L" : (MagnetDir == 2 ? "R" : "S"))}");
                sb.AppendLine($"Charge: {(ChargeSt == 1 ? "ON" : "OFF")}");
                sb.AppendLine($"Cart: {(CartSt == 1 ? "ON" : (CartSt == 0 ? "OFF" : "Unk"))}");
                sb.AppendLine($"Lift: {(LiftSt == 1 ? "UP" : (LiftSt == 0 ? "DOWN" : "Unk"))}");
                sb.Append($"Tag: {LastTag}");
                return sb.ToString();
            }
        }
    }
}
