jest.mock('@/core/gateway/adapters/thirdweb/thirdweb-adapter', () => ({
	ThirdwebAdapter: class ThirdwebAdapter {
		async initialize() {}
		async health() {
			return { status: 'UP' as const };
		}
		async capabilities() {
			return [];
		}
		async validate() {
			return { ok: true };
		}
		async send() {
			return { status: 'SENT' as const, railMessageId: 'mock' };
		}
		async receive() {
			return { status: 'ACK' as const, railMessageId: 'mock' };
		}
		mapStatus(rail: { code: string; description?: string; source?: string }) {
			return { status: 'IN_PROGRESS', railStatus: rail };
		}
		finalityHints() {
			return {};
		}
		errorMap(railError: { code: string; message?: string }) {
			return { errorCode: railError.code || 'UNKNOWN', retryClass: 'MANUAL_REVIEW' as const };
		}
	},
}));

import {
	createGatewayRailAdapter,
	GATEWAY_RAIL_ADAPTER_IDS,
	isGatewayRailAdapterId,
	listGatewayRailAdapterIds,
} from '@/core/gateway/adapters/gateway-adapter-registry';

describe('gateway-adapter-registry', () => {
	it('exports a stable ordered list of rail adapter IDs', () => {
		const ids = listGatewayRailAdapterIds();
		expect(ids.length).toBe(GATEWAY_RAIL_ADAPTER_IDS.length);
		expect(ids).toEqual([...GATEWAY_RAIL_ADAPTER_IDS]);
	});

	it('recognizes known adapter IDs', () => {
		expect(isGatewayRailAdapterId('dbis.adapter.swift-fin')).toBe(true);
		expect(isGatewayRailAdapterId('dbis.adapter.ktt-evidence')).toBe(true);
		expect(isGatewayRailAdapterId('unknown')).toBe(false);
	});

	it('creates adapter instances for each registered id', () => {
		for (const id of listGatewayRailAdapterIds()) {
			const adapter = createGatewayRailAdapter(id);
			expect(adapter).toBeDefined();
			expect(typeof adapter!.validate).toBe('function');
			expect(typeof adapter!.health).toBe('function');
		}
	});

	it('returns undefined for unknown id', () => {
		expect(createGatewayRailAdapter('not-a-rail')).toBeUndefined();
	});
});
