"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotFound = exports.BadRequest = exports.InternalError = exports.deserializeResponseError = exports.serializeResponseError = exports.ResponseError = exports.cResponseErrorVersion = void 0;
const ResponseErrorEnum_1 = require("./enum/ResponseErrorEnum");
const TypeIdentifierEnum_1 = require("./enum/TypeIdentifierEnum");
exports.cResponseErrorVersion = 1;
class ResponseError extends Error {
    constructor(code, appCode, message) {
        super(`Code: ${code}, AppCode: ${appCode}, Message: ${message}`);
        this.Code = code;
        this.AppCode = appCode;
        this.Message = message;
        Object.setPrototypeOf(this, ResponseError.prototype);
    }
}
exports.ResponseError = ResponseError;
function serializeResponseError(stream, obj, root = false) {
    if (root) {
        stream.writeUInt16(TypeIdentifierEnum_1.TypeIdentifierEnum.cResponseError);
    }
    stream.writeUInt8(exports.cResponseErrorVersion);
    stream.writeInt32(obj.Code);
    stream.writeInt32(obj.AppCode);
    stream.writeString(obj.Message);
}
exports.serializeResponseError = serializeResponseError;
function deserializeResponseError(stream) {
    const version = stream.readUInt8();
    if (version > exports.cResponseErrorVersion) {
        throw new Error('ResponseError version mismatch');
    }
    const code = stream.readInt32();
    const appCode = stream.readInt32();
    const message = stream.readString();
    return new ResponseError(code, appCode, message);
}
exports.deserializeResponseError = deserializeResponseError;
function InternalError(message, appCode = 0) {
    return new ResponseError(ResponseErrorEnum_1.ResponseErrorEnum.InternalError, appCode, message);
}
exports.InternalError = InternalError;
function BadRequest(message, appCode = 0) {
    return new ResponseError(ResponseErrorEnum_1.ResponseErrorEnum.BadRequest, appCode, message);
}
exports.BadRequest = BadRequest;
function NotFound(message, appCode = 0) {
    return new ResponseError(ResponseErrorEnum_1.ResponseErrorEnum.NotFound, appCode, message);
}
exports.NotFound = NotFound;
//# sourceMappingURL=ResponseError.js.map