package bx

import (
	"bytes"
	"encoding/binary"
)

type CmdDelDynamicArea struct {
	baseBxCmd
	numbers []byte //编号
}

func NewCmdDelDynamicArea(numbers []byte) CmdDelDynamicArea {
	return CmdDelDynamicArea{
		baseBxCmd: newBaseCmd(CMD_DEL_DYNAMIC_AREA.group, CMD_DEL_DYNAMIC_AREA.code),
		numbers:   numbers,
	}
}

func (cmd CmdDelDynamicArea) Build() []byte {
	w := bytes.NewBuffer(make([]byte, 0, 16))
	binary.Write(w, binary.LittleEndian, cmd.Group())
	binary.Write(w, binary.LittleEndian, cmd.Cmd())
	binary.Write(w, binary.LittleEndian, byte(0x01))
	binary.Write(w, binary.LittleEndian, []byte{0x00, 0x00})
	l := byte(len(cmd.numbers))
	if l == 0 {
		binary.Write(w, binary.LittleEndian, 0xff)
	} else {
		binary.Write(w, binary.LittleEndian, l)
	}
	for _, n := range cmd.numbers {
		binary.Write(w, binary.LittleEndian, n)
	}
	return w.Bytes()
}
