import { Catch, type ArgumentsHost, type ExceptionFilter } from '@nestjs/common';
import { RuntimeApprovalDeniedError } from './runtime-provider-registry.service.js';

/** Maps a consumed/missing runtime approval to a stable HTTP authorization response. */
@Catch(RuntimeApprovalDeniedError)
export class RuntimeApprovalDeniedFilter implements ExceptionFilter {
  catch(_exception: RuntimeApprovalDeniedError, host: ArgumentsHost): void {
    const response = host.switchToHttp().getResponse<{
      status(code: number): { send(body: { statusCode: number; message: string }): void };
    }>();
    response.status(403).send({ statusCode: 403, message: 'Runtime termination approval denied' });
  }
}
