import { __decorate, __metadata, __param } from "tslib";
import { v2 as cloudinary } from 'cloudinary';
import { Inject, Injectable, Scope } from 'graphql-modules';
import { ENVIRONMENT } from '../../shared/tokens.js';
let CloudinaryProvider = class CloudinaryProvider {
    env;
    constructor(env) {
        this.env = env;
        cloudinary.config({
            cloud_name: this.env.cloudinary?.name,
            api_key: this.env.cloudinary?.apiKey,
            api_secret: this.env.cloudinary?.apiSecret,
            secure: true,
        });
    }
    async uploadInvoiceToCloudinary(base64string) {
        try {
            const res = await cloudinary.uploader.upload(base64string, {
                resource_type: 'auto',
                quality: 100,
            });
            const fileUrl = res.url;
            const imageUrl = res.url.split('.').slice(0, -1).join('.') + '.jpg';
            return { fileUrl, imageUrl };
        }
        catch (e) {
            const message = 'Error on uploading file to cloudinary';
            console.error(`${message}: ${e.message}\n${JSON.stringify(e, null, 2)}`);
            throw new Error(message, { cause: e });
        }
    }
};
CloudinaryProvider = __decorate([
    Injectable({
        scope: Scope.Singleton,
        global: true,
    }),
    __param(0, Inject(ENVIRONMENT)),
    __metadata("design:paramtypes", [Object])
], CloudinaryProvider);
export { CloudinaryProvider };
//# sourceMappingURL=cloudinary.js.map