import { IViolations } from './IViolations';
import { IErrorHandler } from '../';

/**
 * Fallback Handler - handles any error not caught by specific handlers
 * This should only be reached for truly unknown errors (plain Error, unknown types, etc.)
 * GenericError and other known error types are handled by their dedicated handlers.
 */
export class GenericErrorHandler implements IErrorHandler {
	canHandle(_: unknown): boolean {
		return true; // Always can handle as fallback
	}

	handle(error: unknown): IViolations {
		// Handle unknown errors
		const errorMessage = error instanceof Error ? error.message : 'Unknown error';
		return [
			{
				messages: { en: 'Internal server error', vi: 'Lỗi máy chủ' },
				type: 'InternalServerError',
				code: 'INTERNAL_SERVER_ERROR',
				additionalData: {
					errors: [],
					stack: error instanceof Error ? error.stack : 'No stack trace',
					message: errorMessage,
				},
			},
		];
	}
}
