import Packet from "../packet";
import Stream from "../stream";

export enum ResultCode {
    SUCCESS = 0,
    ERROR = 1,
    INVALID = 2,
    USERNAME_TAKEN = 3,
}

export class PacketResult extends Packet {

    private resultCode: ResultCode = 0; 

    public getPacketId(): number {
        return 0x02;
    }

    public _receive(stream: Stream): void {
        this.resultCode = stream.readInt16();
    }

    public _send(): Stream {
        const stream = new Stream();
        stream.writeInt16(this.getPacketId());
        stream.writeInt16(this.resultCode);
        return stream;
    }

    public getResultCode(): ResultCode {
        return this.resultCode;
    }

    public setResultCode(resultCode: ResultCode): void {
        this.resultCode = resultCode;
    }
    
}