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

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

/**
 * Represents a qualifier of counter interrogation (QCC) information element.
 */
public class IeQualifierOfCounterInterrogation extends InformationElement {

    private final int request;
    private final int freeze;

    public IeQualifierOfCounterInterrogation(int request, int freeze) {
        this.request = request;
        this.freeze = freeze;
    }

    IeQualifierOfCounterInterrogation(DataInputStream is) throws IOException {
        int b1 = (is.readByte() & 0xff);
        request = b1 & 0x3f;
        freeze = (b1 >> 6) & 0x03;
    }

    @Override
    int encode(byte[] buffer, int i) {
        buffer[i] = (byte) (request | (freeze << 6));
        return 1;
    }

    public int getRequest() {
        return request;
    }

    public int getFreeze() {
        return freeze;
    }

    @Override
    public String toString() {
        return "Qualifier of counter interrogation, request: " + request + ", freeze: " + freeze;
    }
}
