/**
 * INVYONE Template CRUD API 클라이언트
 */

import { apiClient } from './client';

/** 템플릿 목록 조회 */
export async function getTemplateList(params?: Record<string, any>): Promise<Record<string, any>> {
  const res = await apiClient.get('/templates', { params });
  return res.data.data;
}

/** 템플릿 상세 조회 */
export async function getTemplateInfo(templateId: string): Promise<Record<string, any> | null> {
  const res = await apiClient.get(`/templates/${templateId}`);
  if (!res.data.success) return null;
  return res.data.data;
}

/** 템플릿 생성 — template_id 반환 */
export async function insertTemplate(data: Record<string, any>): Promise<Record<string, any>> {
  const res = await apiClient.post('/templates', data);
  return res.data.data;
}

/** 템플릿 수정 */
export async function updateTemplate(templateId: string, data: Record<string, any>): Promise<void> {
  await apiClient.put(`/templates/${templateId}`, data);
}

/** 템플릿 게시 (draft → published) */
export async function publishTemplate(templateId: string): Promise<void> {
  await apiClient.put(`/templates/${templateId}/publish`);
}

/** 템플릿 삭제 (소프트) */
export async function deleteTemplate(templateId: string): Promise<void> {
  await apiClient.delete(`/templates/${templateId}`);
}
