import { IViolations } from '../violations/IViolations';
import { IErrorHandler } from '../index';
import { CircuitBreakerOpenError } from '../ISpecificErrors';
import { createViolation } from '#constants/errors';

/**
 * Circuit Breaker Open Error Handler
 * Handles CircuitBreakerOpenError from the circuit breaker service
 */
export class ExternalServiceErrorHandler implements IErrorHandler {
	canHandle(error: unknown): boolean {
		return error instanceof CircuitBreakerOpenError;
	}

	handle(error: unknown): IViolations {
		return [
			createViolation('CIRCUIT_BREAKER_OPEN', {
				message: (error as Error).message,
			}),
		];
	}
}
