"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.generateDatabaseService = generateDatabaseService;
const generator_1 = require("@postxl/generator");
function generateDatabaseService({ service, config, prismaClient }) {
    const imports = generator_1.ImportGenerator
        //
        .from(service.location)
        .add(prismaClient)
        .add(config);
    return /* ts */ `
import { Injectable, Logger, OnModuleDestroy } from '@nestjs/common'
import { Pool } from 'pg'
import { PrismaPg } from '@prisma/adapter-pg'
${imports.generate()}
@Injectable()
export class ${service.name} extends PrismaClient implements OnModuleDestroy {
  private readonly logger = new Logger(${service.name}.name)
  private readonly pool: Pool

  constructor(config: ${config.name}) {
    const pool = new Pool({ connectionString: config.config.connectionString })
    const adapter = new PrismaPg(pool)

    super({adapter})

    this.pool = pool
  }

  public async onModuleDestroy() {
    await this.$disconnect()
    await this.pool.end()
  }

  // eslint-disable-next-line @typescript-eslint/require-await
  public async emptyDatabase() {
    this.logger.log('TODO: Implement Emptying database')
    // TODO: Implement emptyDb!!!
    // this.logger.log('Emptying database')
    // await this.$executeRaw\`CALL empty_database();\`
    // this.logger.log('Database emptied')
  }
}`;
}
//# sourceMappingURL=database-service.generator.js.map