import JSONFunctions from "../JSONFunctions";
import Typeof from "../Typeof";
export default class HTTPResponse {
    get statusCode() {
        return this._statusCode;
    }
    set statusCode(v) {
        this._statusCode = v;
    }
    get jsonData() {
        return this._jsonData;
    }
    set jsonData(v) {
        this._jsonData = v;
    }
    get data() {
        return this._data;
    }
    set data(v) {
        this._data = v;
    }
    get headers() {
        return this._headers;
    }
    set headers(v) {
        this._headers = v;
    }
    get count() {
        return this._count;
    }
    set count(v) {
        this._count = v;
    }
    get limit() {
        return this._limit;
    }
    set limit(v) {
        this._limit = v;
    }
    get skip() {
        return this._skip;
    }
    set skip(v) {
        this._skip = v;
    }
    get hasMore() {
        return this._hasMore;
    }
    set hasMore(v) {
        this._hasMore = v;
    }
    constructor(statusCode, data, headers) {
        this._statusCode = -1;
        this._headers = {};
        this._count = 0;
        this._limit = 0;
        this._skip = 0;
        /*
         * Optional. Set by analytics list endpoints that skip the expensive
         * COUNT(*) and instead over-fetch by one row. When defined, `count`
         * is only a lower bound — UI should drive next/prev from `hasMore`.
         */
        this._hasMore = undefined;
        this.statusCode = statusCode;
        if (!Array.isArray(data) &&
            Object.keys(data).includes("count") &&
            Object.keys(data).includes("skip") &&
            Object.keys(data).includes("limit")) {
            // likely a list returned.
            this.count = data["count"];
            this.skip = data["skip"];
            this.limit = data["limit"];
            if (Object.keys(data).includes("hasMore")) {
                this.hasMore = data["hasMore"];
            }
            this.jsonData = JSONFunctions.deserializeArray(data["data"]);
        }
        else if (Array.isArray(data)) {
            this.jsonData = JSONFunctions.deserializeArray(data);
        }
        else if (Typeof.String === typeof data) {
            this.jsonData = {
                data,
            };
        }
        else {
            this.jsonData = JSONFunctions.deserialize(data);
        }
        this.headers = headers;
        this.data = this.jsonData;
    }
    isSuccess() {
        return this.statusCode === 200;
    }
    isFailure() {
        return this.statusCode !== 200;
    }
    isNotAuthorized() {
        return this.statusCode === 401;
    }
    isTooManyRequests() {
        return this.statusCode === 429;
    }
    isPaymentDeclined() {
        return this.statusCode === 402;
    }
    isServerError() {
        return this.statusCode === 500;
    }
}
//# sourceMappingURL=HTTPResponse.js.map