namespace InABox.DigitalMatter
{
    public class DMDigitalDataField : DMField
    {
        public override byte Type => 0x02;

        public uint Inputs { get; set; }

        public ushort Outputs { get; set; }

        public ushort Status { get; set; }

        protected override void DoDecode(IDMReadBuffer buffer)
        {
            Inputs = buffer.TakeUInt32();
            Outputs = buffer.TakeUInt16();
            Status = buffer.TakeUInt16();
        }

        protected override void DoEncode(IDMWriteBuffer buffer)
        {
            buffer.AddUInt32(Inputs);
            buffer.AddUInt16(Outputs);
            buffer.AddUInt16(Status);
        }

        public override string ToString()
        {
            return string.Format("In: {0:X8} Out: {1:X4} Status: {2:X4}", Inputs, Outputs, Status);
        }

        public override bool IsValid()
        {
            return Inputs != 0 || Outputs != 0 || Status != 0;
        }
    }
}