import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { secretStoreStatus } from '../../../lib/secret-store.mjs';
import { getRequestTelemetry } from '../../../lib/structured-logger.mjs';

const here = dirname(fileURLToPath(import.meta.url));
const manifest = JSON.parse(readFileSync(join(here, 'module.json'), 'utf8'));

export function createSecurityModule() {
  return {
    manifest,
    lifecycle: {
      async start() {},
      async stop() {},
      async health() {
        const secrets = secretStoreStatus();
        return { ok: true, provider: secrets.provider, encrypted_secrets: secrets.encrypted };
      },
    },
  };
}

export function getSecurityFoundationStatus() {
  return { secrets: secretStoreStatus(), requests: getRequestTelemetry() };
}
