import { DiskSpaceCheck, HealthChecks, MemoryHeapCheck } from '@adonisjs/core/health';
import { DbCheck } from '@adonisjs/lucid/database';
import db from '@adonisjs/lucid/services/db';
import { Chromiumly } from 'chromiumly';
import { version } from '../../lib/version.js';
import { AKEventService } from '../events/event_service.js';
import { AKHttpCheck } from './checks/http.js';
export default class AKHealthChecksController {
    healthChecks = new HealthChecks().register([
        new DiskSpaceCheck().warnWhenExceeds(80).failWhenExceeds(95),
        new MemoryHeapCheck(),
        new DbCheck(db.connection()),
        new AKHttpCheck('Gotenberg', new URL('/health', Chromiumly.getGotenbergEndpoint()), {
            bodyStatusValidValue: 'up',
        }),
        new AKHttpCheck('Insee', new URL('https://entreprise.api.gouv.fr/ping/insee/sirene'), {
            warnIfError: true,
        }),
        ...AKEventService.makeHealthChecks(),
    ]);
    async handle({ response }) {
        const report = await this.healthChecks.run();
        const payload = {
            ...report,
            version,
        };
        if (report.isHealthy)
            return response.ok(payload);
        else
            return response.serviceUnavailable(payload);
    }
}
//# sourceMappingURL=health_checks_controller.js.map