package com.gyee.edge.protocol.iec60870.infoelement;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * Represents a qualifier of set-point command (QOS) information element.
 */
public class IeQualifierOfSetPointCommand extends InformationElement {

    private final int ql;
    private final boolean select;

    public IeQualifierOfSetPointCommand(int ql, boolean select) {
        this.ql = ql;
        this.select = select;
    }

    IeQualifierOfSetPointCommand(DataInputStream is) throws IOException {
        int b1 = (is.readByte() & 0xff);
        ql = b1 & 0x7f;
        select = ((b1 & 0x80) == 0x80);
    }

    @Override
    int encode(byte[] buffer, int i) {
        buffer[i] = (byte) ql;
        if (select) {
            buffer[i] |= 0x80;
        }
        return 1;
    }

    public int getQl() {
        return ql;
    }

    public boolean isSelect() {
        return select;
    }

    @Override
    public String toString() {
        return "Qualifier of set point command, QL: " + ql + ", select: " + select;
    }
}
