import { Injectable } from '@nestjs/common'; import { BaseFactory } from './base.factory'; import { IntegrationStrategy } from '../strategies/integration.strategy'; import { WhatsAppStrategy } from '../strategies/whatsapp/whatsapp.strategy'; import { WhatsAppCloudStrategy } from '../strategies/whatsapp/whatsapp-cloud.strategy'; import { GupshupWhatsAppStrategy } from '../strategies/whatsapp/gupshup-whatsapp.strategy'; import { TubelightWhatsAppStrategy } from '../strategies/whatsapp/tubelight-whatsapp.strategy'; @Injectable() export class WhatsAppFactory implements BaseFactory { constructor( private whatsappStrategy: WhatsAppStrategy, private whatsappCloudStrategy: WhatsAppCloudStrategy, private gupshupWhatsAppStrategy: GupshupWhatsAppStrategy, private tubelightWhatsAppStrategy: TubelightWhatsAppStrategy, ) {} createProvider(service: string, provider: string): IntegrationStrategy { const key = `${service.toLowerCase()}_${provider.toLowerCase()}`; switch (key) { case 'api_whatsapp': return this.whatsappStrategy; case 'api_whatsapp-cloud': case 'api_meta': return this.whatsappCloudStrategy; case 'api_gupshup': return this.gupshupWhatsAppStrategy; case 'api_tubelight': return this.tubelightWhatsAppStrategy; default: throw new Error( `Unsupported WhatsApp service/provider: ${service}/${provider}`, ); } } getSupportedCombinations(): Array<{ service: string; provider: string }> { return [ { service: 'API', provider: 'whatsapp' }, { service: 'API', provider: 'whatsapp-cloud' }, { service: 'API', provider: 'meta' }, { service: 'API', provider: 'gupshup' }, { service: 'API', provider: 'tubelight' }, ]; } validateCombination(service: string, provider: string): boolean { return this.getSupportedCombinations().some( (combo) => combo.service.toLowerCase() === service.toLowerCase() && combo.provider.toLowerCase() === provider.toLowerCase(), ); } }