using System;

namespace arDev
{
    public partial class Narumi
    {

        public class ErrorFlag
        {
            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
            {
                Emergency = 0,
                Overcurrent,
                Charger_run_error,
                Charger_pos_error,
                line_out_error = 4,

                /// <summary>
                /// 기동시 자석 감지 에러
                /// </summary>
                runerror_by_no_magent_line,
                /// <summary>
                /// 호출제어기 통신 오류
                /// </summary>
                controller_comm_error = 11,
                /// <summary>
                /// 도착경보기 통신 오류
                /// </summary>
                arrive_ctl_comm_error,

                /// <summary>
                /// 자동문제어기 통신 오류
                /// </summary>
                door_ctl_comm_error,

                /// <summary>
                /// 자동충전기 통신 오류
                /// </summary>
                charger_comm_error,

                /// <summary>
                /// 교차로 제어기 통신 오류
                /// </summary>
                cross_ctrl_comm_error,
            }

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

            public bool Emergency { get { return GetValue(eflag.Emergency); } }
            public bool Overcurrent { get { return GetValue(eflag.Overcurrent); } }
            public bool Charger_run_error { get { return GetValue(eflag.Charger_run_error); } }
            public bool Charger_pos_error { get { return GetValue(eflag.Charger_pos_error); } }
            public bool line_out_error { get { return GetValue(eflag.line_out_error); } }
            public bool runerror_by_no_magent_line { get { return GetValue(eflag.runerror_by_no_magent_line); } }
            public bool controller_comm_error { get { return GetValue(eflag.controller_comm_error); } }
            public bool arrive_ctl_comm_error { get { return GetValue(eflag.arrive_ctl_comm_error); } }
            public bool door_ctl_comm_error { get { return GetValue(eflag.door_ctl_comm_error); } }
            public bool charger_comm_error { get { return GetValue(eflag.charger_comm_error); } }
            public bool cross_ctrl_comm_error { get { return GetValue(eflag.cross_ctrl_comm_error); } }
            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();
            }
        }

    }


}
