using System;

namespace arDev
{
    public partial class Narumi
    {

        public class SystemFlag1
        {
            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
            {
                Side_Detect_Ignore = 3,
                Melody_check,
                Mark2_check,
                Mark1_check,
                gateout_check,
                Battery_charging = 8,
                re_Start,

                /// <summary>
                /// 전방 감지 무시
                /// </summary>
                front_detect_ignore,

                /// <summary>
                /// 전방장애물감지상태
                /// </summary>
                front_detect_check,

                /// <summary>
                /// 전방감지 후 정지 상태
                /// </summary>
                stop_by_front_detect = 12,
                /// <summary>
                /// 교차로 진입 후 정지 상태
                /// </summary>
                stop_by_cross_in,
                agv_stop,
                agv_run
            }

            public bool GetValue(eflag idx)
            {
                return _value.Get((int)idx);
            }
            public bool GetChanged(eflag idx)
            {
                return _value.GetChanged((int)idx);
            }
            public bool Side_Detect_Ignore { get { return GetValue(eflag.Side_Detect_Ignore); } }
            public bool Melody_check { get { return GetValue(eflag.Melody_check); } }
            public bool Mark2_check { get { return GetValue(eflag.Mark2_check); } }
            public bool Mark1_check { get { return GetValue(eflag.Mark1_check); } }
            public bool gateout_check { get { return GetValue(eflag.gateout_check); } }
            public bool Battery_charging { get { return GetValue(eflag.Battery_charging); } }
            public bool re_Start { get { return GetValue(eflag.re_Start); } }
            public bool front_detect_ignore { get { return GetValue(eflag.front_detect_ignore); } }
            public bool front_detect_check { get { return GetValue(eflag.front_detect_check); } }
            public bool stop_by_front_detect { get { return GetValue(eflag.stop_by_front_detect); } }
            public bool stop_by_cross_in { get { return GetValue(eflag.stop_by_cross_in); } }
            public bool agv_stop { get { return GetValue(eflag.agv_stop); } }
            public bool agv_run { get { return GetValue(eflag.agv_run); } }
            public bool agv_run_manual { get; set; }
            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();
            }

        }

    }


}
