import { die } from '../format.js';
import { resolveChannelProvider, listChannelProviders } from './registry.js';
/** Resolve a channel to its provider, returning the failure instead of exiting. */
export function lookupTransport(channel, meta) {
    const providerName = meta.notify?.transports?.[channel] ?? channel;
    const provider = resolveChannelProvider(providerName);
    if (provider)
        return { providerName, provider };
    return {
        providerName,
        error: `No channel provider '${providerName}'` +
            (providerName === channel ? '' : ` (mapped from channel '${channel}' via notify.transports)`) +
            `. Registered: ${listChannelProviders().join(', ')}.`,
    };
}
/** Interactive-command resolution: an unregistered provider dies loud. */
export function resolveTransport(channel, meta) {
    const { provider, error } = lookupTransport(channel, meta);
    if (!provider)
        die(error);
    return provider;
}
