"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const RoomstayError_1 = require("errors/RoomstayError");
const BaseAPI_1 = __importDefault(require("./BaseAPI"));
class ErrorAPI extends BaseAPI_1.default {
    constructor() {
        super(...arguments);
        this.sendRoomFallbackForm = (hotelId, object) => __awaiter(this, void 0, void 0, function* () {
            try {
                const response = yield fetch(this.getApiPath() + `error/${hotelId}/rate-fallback-form`, {
                    method: 'POST',
                    headers: yield BaseAPI_1.default.getBaseHeaders(),
                    body: JSON.stringify(object),
                });
                if (response.status !== 200) {
                    throw new RoomstayError_1.RoomstayError('Failed to post details');
                }
            }
            catch (ex) {
                throw new RoomstayError_1.RoomstayError('Failed to post details');
            }
        });
        this.sendMemberAreaContactForm = (hotelId, object) => __awaiter(this, void 0, void 0, function* () {
            try {
                const response = yield fetch(this.getApiPath() + `error/${hotelId}/member-area-contact-form`, {
                    method: 'POST',
                    body: JSON.stringify(object),
                });
                if (response.status !== 200) {
                    throw new RoomstayError_1.RoomstayError('Failed to post details');
                }
            }
            catch (ex) {
                throw new RoomstayError_1.RoomstayError('Failed to post details');
            }
        });
        this.statusResponse = undefined;
        this.getStatus = () => __awaiter(this, void 0, void 0, function* () {
            if (this.statusResponse !== undefined) {
                return this.statusResponse;
            }
            const promiseFetch = () => __awaiter(this, void 0, void 0, function* () {
                const response = yield fetch(this.getApiPath() + 'error/status', {
                    method: 'GET',
                    headers: yield BaseAPI_1.default.getBaseHeaders(),
                });
                if (response.status === 204) {
                    return null;
                }
                if (response.status !== 200) {
                    throw new RoomstayError_1.RoomstayError('Failed to get status');
                }
                const responseObject = yield response.json();
                return responseObject;
            });
            this.statusResponse = promiseFetch();
            try {
                return yield this.statusResponse;
            }
            catch (ex) {
                throw new RoomstayError_1.RoomstayError('Failed to get status');
            }
        });
    }
}
exports.default = ErrorAPI;
//# sourceMappingURL=ErrorAPI.js.map