import { apiClient } from '@/lib/api/client'; import { buildQuery, type PaginatedResult } from '@/lib/api/types'; import { TIPO_TEMPLATE_LABEL, TIPOS_TEMPLATE, type AlertTemplate, type CanalTemplate, type TipoTemplate, } from '@/lib/api/alert-templates'; export { CANAIS_TEMPLATE, CANAL_TEMPLATE_LABEL, PLACEHOLDERS_POR_TIPO, TIPO_TEMPLATE_LABEL, } from '@/lib/api/alert-templates'; export type { AlertTemplate, CanalTemplate, TipoTemplate } from '@/lib/api/alert-templates'; /** * `mensalidade_tenant` fica de fora — é o master notificando o tenant sobre * a própria mensalidade, o tenant não define esse template (espelha * `TIPOS_TEMPLATE_TENANT` em `src/modules/alerts/alert-template-tipos.ts`). */ export const TIPOS_TEMPLATE_TENANT = TIPOS_TEMPLATE.filter( (tipo) => tipo !== 'mensalidade_tenant', ); export type TipoTemplateTenant = (typeof TIPOS_TEMPLATE_TENANT)[number]; export const TIPO_TEMPLATE_TENANT_LABEL: Record = Object.fromEntries( TIPOS_TEMPLATE_TENANT.map((tipo) => [tipo, TIPO_TEMPLATE_LABEL[tipo]]), ) as Record; /** Espelha `CreateTenantAlertTemplateDto`/`UpdateTenantAlertTemplateDto`. */ export interface TenantAlertTemplateInput { tipo: TipoTemplateTenant; canal: CanalTemplate; /** Obrigatório só quando `canal === 'email'`. */ assunto?: string; corpo: string; ativo?: boolean; } export interface ListTenantAlertTemplatesParams { tipo?: TipoTemplate; canal?: CanalTemplate; ativo?: boolean; page?: number; limit?: number; } export function listTenantAlertTemplates(params: ListTenantAlertTemplatesParams) { return apiClient.get>( `/tenant/alertas/templates${buildQuery(params)}`, ); } export function createTenantAlertTemplate(input: TenantAlertTemplateInput) { return apiClient.post('/tenant/alertas/templates', input); } export function updateTenantAlertTemplate(id: string, input: Partial) { return apiClient.put(`/tenant/alertas/templates/${id}`, input); } /** Soft delete no backend (`ativo: false`) — não remove o registro. */ export function deleteTenantAlertTemplate(id: string) { return apiClient.delete(`/tenant/alertas/templates/${id}`); }