import { Controller, Get } from "@nestjs/common";
import { ServicesCacheService } from "./application/services-cache.service.js";
import type { ServicesCacheSnapshot } from "./application/services-cache.service.js";
import { Public } from "@bff/modules/auth/decorators/public.decorator.js";

interface ServicesCacheHealthResponse {
  timestamp: string;
  metrics: ServicesCacheSnapshot;
  ttl: {
    servicesSeconds: number | null;
    eligibilitySeconds: number | null;
    staticSeconds: number | null;
    volatileSeconds: number;
  };
}

@Controller("health/services")
@Public()
export class ServicesHealthController {
  constructor(private readonly catalogCache: ServicesCacheService) {}

  @Get("cache")
  getCacheMetrics(): ServicesCacheHealthResponse {
    const ttl = this.catalogCache.getTtlConfiguration();
    return {
      timestamp: new Date().toISOString(),
      metrics: this.catalogCache.getMetrics(),
      ttl,
    };
  }
}
