using System;

namespace arDev
{
    public partial class Narumi
    {

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

            public enum eflag
            {
                Memory_RW_State = 5,
                EXT_IO_Conn_State,
                RFID_Conn_State,
                M5E_Module_Run_State = 8,
                Front_Ultrasonic_Conn_State,
                Front_Untrasonic_Sensor_State,
                Side_Ultrasonic_Conn_State,
                Side_Ultrasonic_Sensor_State = 12,
                Front_Guide_Sensor_State,
                Rear_Guide_Sensor_State,
                Battery_Level_Check
            }

            public bool GetValue(eflag idx)
            {
                return _value.Get((int)idx);
            }
            public bool GetChanged(eflag idx)
            {
                return _value.GetChanged((int)idx);
            }
            public bool Memory_RW_State { get { return GetValue(eflag.Memory_RW_State); } }
            public bool EXT_IO_Conn_State { get { return GetValue(eflag.EXT_IO_Conn_State); } }
            public bool RFID_Conn_State { get { return GetValue(eflag.RFID_Conn_State); } }
            public bool M5E_Module_Run_State { get { return GetValue(eflag.M5E_Module_Run_State); } }
            public bool Front_Ultrasonic_Conn_State { get { return GetValue(eflag.Front_Ultrasonic_Conn_State); } }
            public bool Front_Untrasonic_Sensor_State { get { return GetValue(eflag.Front_Untrasonic_Sensor_State); } }
            public bool Side_Ultrasonic_Conn_State { get { return GetValue(eflag.Side_Ultrasonic_Conn_State); } }
            public bool Side_Ultrasonic_Sensor_State { get { return GetValue(eflag.Side_Ultrasonic_Sensor_State); } }
            public bool Front_Guide_Sensor_State { get { return GetValue(eflag.Front_Guide_Sensor_State); } }
            public bool Rear_Guide_Sensor_State { get { return GetValue(eflag.Rear_Guide_Sensor_State); } }
            public bool Battery_Level_Check { get { return GetValue(eflag.Battery_Level_Check); } }

            public override string ToString()
            {
                //모든사태값을 탭으로 구분하여 문자를 생성한다
                var sb = new System.Text.StringBuilder();
                for(int i = 0; i < 16; i++)
                {
                    var def = Enum.IsDefined(typeof(eflag), i);
                    if (def)
                    {
                        var flag = (eflag)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(eflag), i);
                    if (def)
                    {
                        var flag = (eflag)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();
            }
        }

    }


}
