import { IChannelTestContext } from '../interfaces/ITestContext'; // Mock Channel type for now to avoid import issues interface MockChannel { channelId: string; status?: string; } export class ChannelService { static async createTestChannel(context: IChannelTestContext): Promise { try { // Try to import the real API if available const { Channel } = await import('@techniker-me/pcast-api'); const channelAlias = `UAT#${new Date().toISOString()}#${context.streamKind}`; const channelDescription = `UAT#SubscribeWorkflow#${context.streamKind}`; const channelOptions: string[] = []; const channel = await context.pcastApi.createChannel(channelAlias, channelDescription, channelOptions); // Add cleanup task context.addCleanupTask(async () => { console.log(`${new Date().toISOString()} [SubscribeWorkflow] [cleanup] deleting channel [${JSON.stringify(channel, null, 2)}]`); try { const deleteResponse = await context.pcastApi.deleteChannel(channel.channelId); if (deleteResponse.status !== 'ok') { throw new Error(`[SubscribeWorkflow] [cleanup] Error: Unable to delete test channel due to [${JSON.stringify(deleteResponse, null, 2)}]`); } } catch (error) { console.error('Failed to delete channel during cleanup:', error); } }); return channel; } catch (error) { console.warn('Real PCast API not available, using mock channel:', error); // Return mock channel for testing const mockChannel: MockChannel = { channelId: `mock-${Date.now()}-${context.streamKind}` }; // Add mock cleanup task context.addCleanupTask(async () => { console.log(`${new Date().toISOString()} [SubscribeWorkflow] [cleanup] cleaning up mock channel [${mockChannel.channelId}]`); }); return mockChannel; } } }