"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZendeskClient = void 0;
const axios_1 = __importDefault(require("axios"));
const types_1 = require("./types");
class ZendeskBaseAPI {
    constructor({ baseUrl, apiToken, tokenHeaderKey, }) {
        this.post = async (url, { body }) => {
            return await axios_1.default.post(`${this._baseUrl}/${url}`, body, {
                headers: this._headers,
            });
        };
        this.put = async (url, { body }) => {
            return await axios_1.default.put(`${this._baseUrl}/${url}`, body, {
                headers: this._headers,
            });
        };
        this.patch = async (url, { body }) => {
            return await axios_1.default.patch(`${this._baseUrl}/${url}`, body, {
                headers: this._headers,
            });
        };
        this.get = async (url) => {
            return await axios_1.default.get(`${this._baseUrl}/${url}`, {
                headers: this._headers,
            });
        };
        this.delete = async (url) => {
            return await axios_1.default.delete(`${this._baseUrl}/${url}`, {
                headers: this._headers,
            });
        };
        this._baseUrl = baseUrl;
        this._token = apiToken;
        this._headers = {
            'Content-Type': 'application/json; charset=utf8',
            Accept: ' application/json',
            [tokenHeaderKey]: this._token,
        };
    }
}
class ZendeskSalesAPI {
    constructor({ apiToken }) {
        this.createTask = async (task) => {
            return await this._baseApi.post('v2/tasks', {
                body: {
                    data: task,
                    meta: {
                        type: types_1.ResourceType.TASK,
                    },
                },
            });
        };
        this.updateTask = async (id, task) => {
            return await this._baseApi.put(`v2/tasks/${id}`, {
                body: {
                    data: task,
                    meta: {
                        type: types_1.ResourceType.TASK,
                    },
                },
            });
        };
        this._baseApi = new ZendeskBaseAPI({
            baseUrl: `https://api.getbase.com`,
            apiToken: `Bearer ${apiToken}`,
            tokenHeaderKey: 'Authorization',
        });
    }
}
class ZendeskClient {
    constructor({ salesApiToken }) {
        this.salesApi = new ZendeskSalesAPI({ apiToken: salesApiToken });
    }
}
exports.ZendeskClient = ZendeskClient;
//# sourceMappingURL=client.js.map