import request from '@/utils/request'
import type {
  PromptTemplate,
  PromptTemplateDetail,
  PromptTemplateCreate,
  PromptTemplateUpdate,
  PromptTemplateListResponse,
  PublishRequest,
  RollbackRequest
} from '@/types/prompt-template'

export function listPromptTemplates(params?: { scene?: string }): Promise<PromptTemplateListResponse> {
  return request({
    url: '/admin/prompt-templates',
    method: 'get',
    params
  })
}

export function getPromptTemplate(tplId: string): Promise<PromptTemplateDetail> {
  return request({
    url: `/admin/prompt-templates/${tplId}`,
    method: 'get'
  })
}

export function createPromptTemplate(data: PromptTemplateCreate): Promise<PromptTemplate> {
  return request({
    url: '/admin/prompt-templates',
    method: 'post',
    data
  })
}

export function updatePromptTemplate(tplId: string, data: PromptTemplateUpdate): Promise<PromptTemplate> {
  return request({
    url: `/admin/prompt-templates/${tplId}`,
    method: 'put',
    data
  })
}

export function deletePromptTemplate(tplId: string): Promise<void> {
  return request({
    url: `/admin/prompt-templates/${tplId}`,
    method: 'delete'
  })
}

export function publishPromptTemplate(tplId: string, data: PublishRequest): Promise<{ success: boolean; message: string }> {
  return request({
    url: `/admin/prompt-templates/${tplId}/publish`,
    method: 'post',
    data
  })
}

export function rollbackPromptTemplate(tplId: string, data: RollbackRequest): Promise<{ success: boolean; message: string }> {
  return request({
    url: `/admin/prompt-templates/${tplId}/rollback`,
    method: 'post',
    data
  })
}

export type {
  PromptTemplate,
  PromptTemplateDetail,
  PromptTemplateCreate,
  PromptTemplateUpdate,
  PromptTemplateListResponse
}
