/** Health controller for the {{ module_title }} NestJS integration. */

import {
  Controller,
  Get,
  HttpCode,
  HttpStatus,
} from "@nestjs/common";

import { {{ module_class_name }}Service } from "./passwordless.service";

type PasswordlessHealthPayload = {
  status: "ok" | "degraded";
  metadata: Record<string, unknown>;
  issues: string[];
};

@Controller("api/health/module")
export class {{ module_class_name }}HealthController {
  constructor(private readonly service: {{ module_class_name }}Service) {}

  @Get("passwordless")
  @HttpCode(HttpStatus.OK)
  getModuleHealth(): PasswordlessHealthPayload {
    const metadata = this.service.describe();
    const issues: string[] = [];

  if (!Array.isArray(metadata["deliveryMethods"]) || metadata["deliveryMethods"].length === 0) {
      issues.push("no_delivery_methods_configured");
    }

    const status: "ok" | "degraded" = issues.length === 0 ? "ok" : "degraded";
    return {
      status,
      metadata,
      issues,
    };
  }
}
