import { ApiError, request } from './client'; import type { components } from './generated/v1'; export type ChannelTemplate = components['schemas']['ChannelTemplateResponseModel']; export type CreateChannelTemplateRequest = components['schemas']['CreateChannelTemplateRequest']; export function getChannelTemplates(): Promise { return request('/api/channel-templates'); } export async function getDefaultChannelTemplate(): Promise { try { return await request('/api/channel-templates/default'); } catch (error) { if (error instanceof ApiError && error.status === 404) { return null; } throw error; } } export function createChannelTemplate(body: CreateChannelTemplateRequest): Promise { return request('/api/channel-templates', { body, method: 'POST' }); } export function messageFromChannelTemplateError(error: unknown, fallback = 'Unable to load channel templates'): string { if (error instanceof ApiError) { return error.detail ?? error.message; } if (error instanceof Error) { return error.message; } return fallback; }