import client from './client';
import type { PaginatedResponse } from './types';

export interface MessageTemplateInfo {
  id: string;
  tenant_id: string;
  name: string;
  code: string;
  channel: string;
  title_template: string;
  body_template: string;
  language: string;
  created_at: string;
  updated_at: string;
}

export interface CreateTemplateRequest {
  name: string;
  code: string;
  channel?: string;
  title_template: string;
  body_template: string;
  language?: string;
}

export async function listTemplates(page = 1, pageSize = 20) {
  const { data } = await client.get<{ success: boolean; data: PaginatedResponse<MessageTemplateInfo> }>(
    '/message-templates',
    { params: { page, page_size: pageSize } },
  );
  return data.data;
}

export async function createTemplate(req: CreateTemplateRequest) {
  const { data } = await client.post<{ success: boolean; data: MessageTemplateInfo }>(
    '/message-templates',
    req,
  );
  return data.data;
}
