package pl.grzeslowski.jsupla.protocol.api.structs.ds;

import pl.grzeslowski.jsupla.protocol.api.calltypes.DeviceServerCallType;

import static pl.grzeslowski.jsupla.Preconditions.checkArrayLength;
import static pl.grzeslowski.jsupla.Preconditions.positive;
import static pl.grzeslowski.jsupla.protocol.api.calltypes.DeviceServerCallType.SUPLA_DS_CALL_REGISTER_DEVICE_D;
import static pl.grzeslowski.jsupla.protocol.api.consts.JavaConsts.BYTE_SIZE;
import static pl.grzeslowski.jsupla.protocol.api.consts.ProtoConsts.*;

/**
 * @since ver. 7
 */
public final class SuplaRegisterDeviceD implements DeviceServer {
    public final byte[] email;
    /**
     * UTF-8.
     */
    public final byte[] authKey;
    public final byte[] guid;
    /**
     * UTF-8.
     */
    public final byte[] name;
    public final byte[] softVer;
    public final byte[] serverName;
    /**
     * unsigned.
     */
    public final short channelCount;
    public final SuplaDeviceChannelB[] channels;

    public SuplaRegisterDeviceD(byte[] email, byte[] authKey, byte[] guid, byte[] name, byte[] softVer, byte[] serverName,
                                short channelCount, SuplaDeviceChannelB[] channels) {
        this.email = checkArrayLength(email, SUPLA_EMAIL_MAXSIZE);
        this.authKey = checkArrayLength(authKey, SUPLA_AUTHKEY_SIZE);
        this.guid = checkArrayLength(guid, SUPLA_GUID_SIZE);
        this.name = checkArrayLength(name, SUPLA_DEVICE_NAME_MAXSIZE);
        this.softVer = checkArrayLength(softVer, SUPLA_SOFTVER_MAXSIZE);
        this.serverName = checkArrayLength(serverName, SUPLA_SERVER_NAME_MAXSIZE);
        this.channelCount = positive(channelCount);
        this.channels = checkArrayLength(channels, channelCount);
    }

    @Override
    public DeviceServerCallType callType() {
        return SUPLA_DS_CALL_REGISTER_DEVICE_D;
    }

    @Override
    public int size() {
        return BYTE_SIZE * (SUPLA_EMAIL_MAXSIZE + SUPLA_AUTHKEY_SIZE
                + SUPLA_GUID_SIZE + SUPLA_DEVICE_NAME_MAXSIZE
                + SUPLA_SOFTVER_MAXSIZE + SUPLA_SERVER_NAME_MAXSIZE) +
                BYTE_SIZE + channels.length * SuplaDeviceChannelB.SIZE;
    }
}

@@ -124,16 +124,42 @@
 lType;%0A%0A
+import java.util.Arrays;%0A%0A
 import s
@@ -2195,11 +2195,1317 @@
 E;%0A    %7D
+%0A%0A    @Override%0A    public boolean equals(Object o) %7B%0A        if (this == o) return true;%0A        if (o == null %7C%7C getClass() != o.getClass()) return false;%0A        SuplaRegisterDeviceD that = (SuplaRegisterDeviceD) o;%0A        return channelCount == that.channelCount &&%0A                Arrays.equals(email, that.email) &&%0A                Arrays.equals(authKey, that.authKey) &&%0A                Arrays.equals(guid, that.guid) &&%0A                Arrays.equals(name, that.name) &&%0A                Arrays.equals(softVer, that.softVer) &&%0A                Arrays.equals(serverName, that.serverName) &&%0A                Arrays.equals(channels, that.channels);%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return Arrays.hashCode(guid);%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22SuplaRegisterDeviceD%7B%22 +%0A                %22email=%22 + Arrays.toString(email) +%0A                %22, authKey=%22 + Arrays.toString(authKey) +%0A                %22, guid=%22 + Arrays.toString(guid) +%0A                %22, name=%22 + Arrays.toString(name) +%0A                %22, softVer=%22 + Arrays.toString(softVer) +%0A                %22, serverName=%22 + Arrays.toString(serverName) +%0A                %22, channelCount=%22 + channelCount +%0A                %22, channels=%22 + Arrays.toString(channels) +%0A                '%7D';%0A    %7D
 %0A%7D%0A

Add toString, equals and hasCode