import { Router } from 'express';
import { DataSource } from 'typeorm';
import { HealthService } from './health.service';
import { HealthController } from './health.controller';

export interface HealthModuleOptions {
  dataSource: DataSource;
  basePath?: string;
}

export class HealthModule {
  public router: Router;
  public healthService: HealthService;
  private basePath: string;

  constructor(options: HealthModuleOptions) {
    this.basePath = options.basePath || '';
    this.router = Router();
    this.initializeServices(options.dataSource);
    this.initializeRoutes();
  }

  private initializeServices(dataSource: DataSource): void {
    this.healthService = new HealthService(dataSource);
  }

  private initializeRoutes(): void {
    const healthController = new HealthController(this.healthService);
    this.router.use(`${this.basePath}/health`, healthController.router);
  }
}

export { HealthService } from './health.service';
export { HealthController } from './health.controller';
