"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeAPIClient = exports.ZendeskAPIClient = void 0;
const axios_1 = __importDefault(require("axios"));
const settings_1 = require("../../settings");
class ZendeskAPIClient {
    constructor(subdomain, userEmail, apiToken) {
        const credentials = `${userEmail}/token:${apiToken}`;
        const encodedCredentials = Buffer.from(credentials).toString('base64');
        this.client = axios_1.default.create({
            baseURL: `https://${subdomain}.zendesk.com`,
            headers: {
                Authorization: `Basic ${encodedCredentials}`,
                'Content-Type': 'application/json',
            },
        });
    }
    async createTicket(data) {
        const response = await this.client.post('/api/v2/tickets', { ticket: data });
        return response.data;
    }
    async deleteTicket(ticketId) {
        await this.client.delete(`/api/v2/tickets/${ticketId}`);
    }
    async updateTicket(ticketId, data) {
        await this.client.put(`/api/v2/tickets/${ticketId}`, { ticket: data });
    }
}
exports.ZendeskAPIClient = ZendeskAPIClient;
const makeAPIClient = (payloadSettings) => {
    const { subdomain, user_email, api_token } = settings_1.SettingsValidationSchema.parse(payloadSettings);
    return new ZendeskAPIClient(subdomain, user_email, api_token);
};
exports.makeAPIClient = makeAPIClient;
//# sourceMappingURL=client.js.map