import { VoiceProviderRegistry } from './provider-registry.js';
export class VoiceService {
    registry;
    constructor(registry) {
        this.registry = registry;
    }
    async getStatus(enabled) {
        const providers = await this.registry.status();
        return {
            enabled,
            providerCount: providers.length,
            providers,
            note: 'Voice capture is intentionally external to the SDK host process; terminal, web, or companion clients can stream audio into these provider-backed APIs.',
        };
    }
    async listVoices(providerId) {
        const providers = providerId
            ? [this.registry.get(providerId)].filter((provider) => provider !== null)
            : this.registry.list().map((entry) => this.registry.get(entry.id)).filter((provider) => provider !== null);
        const voices = [];
        for (const provider of providers) {
            if (!provider.listVoices)
                continue;
            voices.push(...await provider.listVoices());
        }
        return voices.sort((a, b) => a.label.localeCompare(b.label) || a.id.localeCompare(b.id));
    }
    async synthesize(providerId, request) {
        const provider = this.registry.findProvider('tts', providerId);
        if (!provider?.synthesize) {
            throw new Error(providerId ? `Voice TTS provider unavailable: ${providerId}` : 'No voice TTS provider is registered');
        }
        return provider.synthesize(request);
    }
    async transcribe(providerId, request) {
        const provider = this.registry.findProvider('stt', providerId);
        if (!provider?.transcribe) {
            throw new Error(providerId ? `Voice STT provider unavailable: ${providerId}` : 'No voice STT provider is registered');
        }
        return provider.transcribe(request);
    }
    async openRealtimeSession(providerId, request) {
        const provider = this.registry.findProvider('realtime', providerId);
        if (!provider?.openRealtimeSession) {
            throw new Error(providerId ? `Voice realtime provider unavailable: ${providerId}` : 'No voice realtime provider is registered');
        }
        return provider.openRealtimeSession(request);
    }
}
