import * as firebaseAdmin from 'firebase-admin/app';
import _ from 'lodash';
import env from '../../env.js';
import { deviceTokenController } from './device_token_controller.js';
import { deviceTokenService } from './device_token_service.js';
import { AKPushNotificationService } from './push_notification_service.js';
export let DeviceTokenController;
export default class AKPushNotificationProvider {
    app;
    constructor(app) {
        this.app = app;
    }
    register() {
        this.app.container.singleton('akago.device_token.service.class', async (_resolver) => {
            const config = this.app.config.get('akago_auth');
            const userClass = await config.userClass.resolver(this.app);
            return deviceTokenService(userClass);
        });
        const gcpKeyBase64 = env.get('GOOGLE_CLOUD_KEY');
        const gcpKey = JSON.parse(Buffer.from(gcpKeyBase64, 'base64').toString('utf-8'));
        let { projectId, clientEmail, privateKey } = _.mapKeys(gcpKey, (__, k) => _.camelCase(k));
        firebaseAdmin.initializeApp({
            credential: firebaseAdmin.cert({ projectId, clientEmail, privateKey }),
        });
        this.app.container.singleton('akago.push_notification.service', async (resolver) => {
            const tokenServiceClass = await resolver.make('akago.device_token.service.class');
            const tokenService = new tokenServiceClass();
            return new AKPushNotificationService(tokenService);
        });
    }
    async boot() {
        const deviceTokenService = await this.app.container.make('akago.device_token.service.class');
        DeviceTokenController = deviceTokenController(deviceTokenService);
    }
}
//# sourceMappingURL=provider.js.map