using System;

namespace arDev
{
    public partial class Narumi
    {
        public enum eSignal1
        {
            front_gate_out = 0,
            rear_gte_out,
            mark_sensor_1,
            mark_sensor_2,
            lift_down_sensor,
            lift_up_sensor,
            magnet_relay,
            charger_align_sensor,
        }
        public enum eSignal2
        {
            cart_detect1 = 0,
            cart_detect2,
        }

        public class Signal1
        {
            private COMM.Flag _value { get; set; } = new COMM.Flag(8);
            public void SetValue(Int16 value) { this._value.writeValue(value); }
            public UInt16 Value
            {
                get
                {
                    return (UInt16)_value.Value;
                }
            }


            public bool GetValue(eSignal1 idx)
            {
                return _value.Get((int)idx);
            }
            public bool GetChanged(eSignal1 idx)
            {
                return _value.GetChanged((int)idx);
            }

            public Boolean front_gate_out { get { return GetValue(eSignal1.front_gate_out); } }
            public Boolean rear_sensor_out { get { return GetValue(eSignal1.rear_gte_out); } }
            public Boolean mark_sensor_1 { get { return GetValue(eSignal1.mark_sensor_1); } }
            public Boolean mark_sensor_2 { get { return GetValue(eSignal1.mark_sensor_2); } }
            public Boolean mark_sensor { get { return mark_sensor_1 || mark_sensor_2; } }
            public Boolean charger_align_sensor { get { return GetValue(eSignal1.charger_align_sensor); } }
            public Boolean lift_up { get { return GetValue(eSignal1.lift_up_sensor); } }
            public Boolean lift_down { get { return GetValue(eSignal1.lift_down_sensor); } }
            public Boolean magnet_on { get { return GetValue(eSignal1.magnet_relay); } }
       
            public override string ToString()
            {
                //모든사태값을 탭으로 구분하여 문자를 생성한다
                var sb = new System.Text.StringBuilder();
                for (int i = 0; i < 16; i++)
                {
                    var def = Enum.IsDefined(typeof(eSignal1), i);
                    if (def)
                    {
                        var flag = (eSignal1)i;
                        var value = _value.Get(i);
                        sb.AppendLine($"[{i:00}][{flag}] : {value}");
                    }

                }
                return sb.ToString();
            }

            public string ToRtfString()
            {
                var sb = new System.Text.StringBuilder();
                sb.AppendLine(@"{\rtf1\ansi\deff0");
                sb.AppendLine(@"{\colortbl ;\red0\green0\blue255;}"); // Color 1 = Blue

                for (int i = 0; i < 16; i++)
                {
                    var def = Enum.IsDefined(typeof(eSignal1), i);
                    if (def)
                    {
                        var flag = (eSignal1)i;
                        var value = _value.Get(i);
                        string line = $"[{i:00}][{flag}] : {value}";

                        // : true가 포함된 줄은 파란색
                        if (value == true)
                        {
                            sb.AppendLine(@"\cf1 " + line + @"\cf0\line");
                        }
                        else
                        {
                            sb.AppendLine(line + @"\line");
                        }
                    }
                }

                sb.AppendLine("}");
                return sb.ToString();
            }

        }


        public class Signal2
        {
            private COMM.Flag _value { get; set; } = new COMM.Flag(8);
            public void SetValue(Int16 value) { this._value.writeValue(value); }
            public UInt16 Value
            {
                get
                {
                    return (UInt16)_value.Value;
                }
            }
         

            public bool GetValue(eSignal2 idx)
            {
                return _value.Get((int)idx);
            }
            public bool GetChanged(eSignal2 idx)
            {
                return _value.GetChanged((int)idx);
            }

       
            public Boolean cart_detect1 { get { return GetValue(eSignal2.cart_detect1); } }
            public Boolean cart_detect2 { get { return  GetValue(eSignal2.cart_detect2); } }
            public override string ToString()
            {
                //모든사태값을 탭으로 구분하여 문자를 생성한다
                var sb = new System.Text.StringBuilder();
                for (int i = 0; i < 16; i++)
                {
                    var def = Enum.IsDefined(typeof(eSignal2), i);
                    if(def)
                    {
                        var flag = (eSignal2)i;
                        var value = _value.Get(i);
                        sb.AppendLine($"[{i:00}][{flag}] : {value}");
                    }

                }
                return sb.ToString();
            }

            public string ToRtfString()
            {
                var sb = new System.Text.StringBuilder();
                sb.AppendLine(@"{\rtf1\ansi\deff0");
                sb.AppendLine(@"{\colortbl ;\red0\green0\blue255;}"); // Color 1 = Blue

                for (int i = 0; i < 16; i++)
                {
                    var def = Enum.IsDefined(typeof(eSignal2), i);
                    if (def)
                    {
                        var flag = (eSignal2)i;
                        var value = _value.Get(i);
                        string line = $"[{i:00}][{flag}] : {value}";

                        // : true가 포함된 줄은 파란색
                        if (value == true)
                        {
                            sb.AppendLine(@"\cf1 " + line + @"\cf0\line");
                        }
                        else
                        {
                            sb.AppendLine(line + @"\line");
                        }
                    }
                }

                sb.AppendLine("}");
                return sb.ToString();
            }

        }

    }


}
