import { Controller, Get } from '@nestjs/common';
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { HealthCheck, HealthCheckService } from '@nestjs/terminus';
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { PrismaHealthIndicator } from './infrastructure/prisma.health';
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import { RedisHealthIndicator } from './infrastructure/redis.health';

@Controller('health')
export class HealthController {
  constructor(
    private readonly health: HealthCheckService,
    private readonly prismaHealth: PrismaHealthIndicator,
    private readonly redisHealth: RedisHealthIndicator,
  ) {}

  /** Liveness probe — always returns 200 if the process is running */
  @Get()
  @HealthCheck()
  liveness() {
    return this.health.check([]);
  }

  /** Readiness probe — checks DB and Redis connectivity */
  @Get('ready')
  @HealthCheck()
  readiness() {
    return this.health.check([
      () => this.prismaHealth.isHealthy('database'),
      () => this.redisHealth.isHealthy('redis'),
    ]);
  }

  /** Database readiness — checks PostgreSQL connectivity */
  @Get('db')
  @HealthCheck()
  database() {
    return this.health.check([
      () => this.prismaHealth.isHealthy('database'),
    ]);
  }

  /** Redis readiness — checks Redis connectivity */
  @Get('redis')
  @HealthCheck()
  redis() {
    return this.health.check([
      () => this.redisHealth.isHealthy('redis'),
    ]);
  }
}
