package com.nokia.sms.sgip.message;

import java.io.IOException;

import org.apache.mina.core.buffer.IoBuffer;

import com.nokia.sms.sgip.codec.MessageUtil;

public class SubmitResponseMessage extends SgipMessage {
    public static final int COMMAND_ID = -2147483645;
    private byte operateResult;
    private String reserve;

    public IoBuffer getBuffer() {
        if (this.head == null) {
            this.head = new Head();
        }
        this.head.setCommandId(-2147483645);
        this.head.setMessageLength(29);
        IoBuffer buffer = IoBuffer.allocate(29);
        buffer.put(this.head.getBuffer());
        buffer.put(this.operateResult);
        int oldPosition = buffer.position();
        if (this.reserve != null) {
            buffer.put(this.reserve.getBytes());
        }
        buffer.position(oldPosition + 8);
        return buffer.flip();
    }

    public void parseBody(IoBuffer ioBuffer)
            throws IOException {
        this.operateResult = ioBuffer.get();
        this.reserve = ioBuffer.getString(8, MessageUtil.gbkDecoder);
    }

    public void setOperateResult(byte result) {
        this.operateResult = result;
    }

    public byte getOperateResult() {
        return this.operateResult;
    }

    public String getReserve() {
        return this.reserve;
    }

    public void setReserve(String reserve) {
        this.reserve = reserve;
    }

    public String toString() {
        return "SubmitResponseMessage [head=" + this.head + ", operateResult=" + this.operateResult + ", reserve="
                + this.reserve + "]";
    }
}
