import request from '@/utils/request'
import type {
  DecompositionTemplate,
  DecompositionTemplateDetail,
  DecompositionTemplateCreate,
  DecompositionTemplateUpdate,
  DecompositionTemplateListResponse
} from '@/types/decomposition-template'

export const decompositionTemplateApi = {
  list: (params?: { scene?: string; status?: string }) =>
    request<DecompositionTemplateListResponse>({
      method: 'GET',
      url: '/admin/decomposition-templates',
      params
    }),

  get: (id: string) =>
    request<DecompositionTemplateDetail>({
      method: 'GET',
      url: `/admin/decomposition-templates/${id}`
    }),

  create: (data: DecompositionTemplateCreate) =>
    request<DecompositionTemplate>({
      method: 'POST',
      url: '/admin/decomposition-templates',
      data
    }),

  update: (id: string, data: DecompositionTemplateUpdate) =>
    request<DecompositionTemplate>({
      method: 'PUT',
      url: `/admin/decomposition-templates/${id}`,
      data
    }),

  delete: (id: string) =>
    request({ method: 'DELETE', url: `/admin/decomposition-templates/${id}` }),

  activate: (id: string) =>
    request<DecompositionTemplate>({
      method: 'POST',
      url: `/admin/decomposition-templates/${id}/activate`
    }),

  archive: (id: string) =>
    request<DecompositionTemplate>({
      method: 'POST',
      url: `/admin/decomposition-templates/${id}/archive`
    }),

  rollback: (id: string, version: number) =>
    request<DecompositionTemplate>({
      method: 'POST',
      url: `/admin/decomposition-templates/${id}/rollback`,
      data: { version }
    })
}
