import { RequestParams } from './http-client'
import { ContentType, HttpClient } from './http-client'
import type {
  ProtocolDto,
  ProtocolPageInput,
  ProtocolPageResponse,
  ProtocolOutput,
  ProtocolAddInput,
  ProtocolUpdateInput
} from '/@/api/types/protocolType'

export class ProtocolApi extends HttpClient {
  /**
   * 获取分页列表
   */
  getPage = (data: ProtocolPageInput, params: RequestParams = {}) =>
    this.request<ProtocolPageResponse>({
      path: `/api/admin/protocol/get-page`,
      method: 'POST',
      body: data,
      type: ContentType.Json,
      ...params,
    })

  /**
   * 获取单条数据
   */
  get = (params: { id: number }, requestParams: RequestParams = {}) =>
    this.request<ProtocolOutput>({
      path: `/api/admin/protocol/get`,
      method: 'GET',
      query: { id: params.id },
      ...requestParams,
    })

  /**
   * 新增
   */
  add = (data: ProtocolAddInput, params: RequestParams = {}) =>
    this.request<any>({
      path: `/api/admin/protocol/add`,
      method: 'POST',
      body: data,
      type: ContentType.Json,
      ...params,
    })

  /**
   * 更新
   */
  update = (data: ProtocolUpdateInput, params: RequestParams = {}) =>
    this.request<any>({
      path: `/api/admin/protocol/update`,
      method: 'PUT',
      body: data,
      type: ContentType.Json,
      ...params,
    })

  /**
   * 软删除
   */
  softDelete = (params: { id: number }, requestParams: RequestParams = {}) =>
    this.request<any>({
      path: `/api/admin/protocol/soft-delete`,
      method: 'DELETE',
      query: params,
      ...requestParams,
    })

  /**
   * 复制培养方案
   */
  copy = (params: { id: number; reactorId: number }, requestParams: RequestParams = {}) =>
    this.request<any>({
      path: `/api/admin/protocol/copy`,
      method: 'POST',
      body: params,
      type: ContentType.Json,
      ...requestParams,
    })

  /**
   * 切换培养方案状态
   */
  toggleStatus = (params: { id: number; isEnabled: boolean }, requestParams: RequestParams = {}) =>
    this.request<any>({
      path: `/api/admin/protocol/toggle-status`,
      method: 'POST',
      query: params,
      ...requestParams,
    })
} 