import { Controller, Get } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { sql } from 'drizzle-orm';
import { Public } from '@/common/auth/decorators';
import { DbService } from '@/common/db/db.service';

@ApiTags('health')
@Controller('health')
export class HealthController {
  constructor(private readonly db: DbService) {}

  @Public()
  @Get()
  async health() {
    const started = Date.now();
    await this.db.db.execute(sql`select 1`);
    return { status: 'ok', db: 'ok', dbLatencyMs: Date.now() - started, time: new Date().toISOString(), version: process.env.npm_package_version ?? '0.1.0' };
  }

  @Public()
  @Get('ready')
  ready() {
    return { ready: true };
  }
}
