"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 });
exports.DeleteMemberCard = exports.EditMemberCard = exports.AddMemberCard = exports.UpdateMemberDetails = exports.GetMemberDetails = void 0;
const BaseAPI_1 = __importDefault(require("../BaseAPI"));
const config_1 = require("../../config");
const get = (path) => __awaiter(void 0, void 0, void 0, function* () {
    const headers = yield BaseAPI_1.default.getBaseHeaders();
    return (fetch(`${config_1.RoomstayGlobalConfig.RoomstayMemmberApiUrl}${path}`, {
        headers,
    })
        .then((response) => response.json())
        // TODO: Some proper form of error handling...
        .catch(console.error));
});
const post = (path, body) => __awaiter(void 0, void 0, void 0, function* () {
    const headers = yield BaseAPI_1.default.getBaseHeaders();
    return (fetch(`${config_1.RoomstayGlobalConfig.RoomstayMemmberApiUrl}${path}`, {
        headers,
        method: 'POST',
        body: JSON.stringify(body),
    })
        .then((response) => response.json())
        // TODO: Some proper form of error handling...
        .catch(console.error));
});
const put = (path, body) => __awaiter(void 0, void 0, void 0, function* () {
    const headers = yield BaseAPI_1.default.getBaseHeaders();
    return (fetch(`${config_1.RoomstayGlobalConfig.RoomstayMemmberApiUrl}${path}`, {
        headers,
        method: 'PUT',
        body: JSON.stringify(body),
    })
        .then((response) => response.json())
        // TODO: Some proper form of error handling...
        .catch(console.error));
});
const del = (path, body) => __awaiter(void 0, void 0, void 0, function* () {
    const headers = yield BaseAPI_1.default.getBaseHeaders();
    return (fetch(`${config_1.RoomstayGlobalConfig.RoomstayMemmberApiUrl}${path}`, {
        headers,
        method: 'DELETE',
        body: JSON.stringify(body),
    })
        .then((response) => response.json())
        // TODO: Some proper form of error handling...
        .catch(console.error));
});
const GetMemberDetails = () => __awaiter(void 0, void 0, void 0, function* () {
    return (yield get(''));
});
exports.GetMemberDetails = GetMemberDetails;
const UpdateMemberDetails = (newMemberDetails) => __awaiter(void 0, void 0, void 0, function* () {
    return put('', newMemberDetails);
});
exports.UpdateMemberDetails = UpdateMemberDetails;
const AddMemberCard = (card) => __awaiter(void 0, void 0, void 0, function* () {
    // TODO: Omit username from this post data
    return post(`cards/`, card);
});
exports.AddMemberCard = AddMemberCard;
const EditMemberCard = (card) => __awaiter(void 0, void 0, void 0, function* () {
    return put(`cards/${card.cardId}`, card);
});
exports.EditMemberCard = EditMemberCard;
const DeleteMemberCard = (card) => __awaiter(void 0, void 0, void 0, function* () {
    return del(`cards/${card.cardId}`, card);
});
exports.DeleteMemberCard = DeleteMemberCard;
//# sourceMappingURL=MembersServiceAPI.js.map