import request from './request'
import type { OriginGood, OriginGoodsTreeResponse, OriginGoodTagsResult, PaginatedResult } from '@/types'

export const originGoodsApi = {
  getTree: () => {
    return request.get<any, OriginGoodsTreeResponse>('/origin-goods/tree')
  },

  getOriginGoodsList: (params: { page?: number; pageSize?: number; keyword?: string }) => {
    return request.get<any, PaginatedResult<OriginGood>>('/origin-goods', { params })
  },

  // 单链接详情（detail + variants，成员展开面板用）
  getOriginGood: (id: string) => {
    return request.get<any, Record<string, any>>(`/origin-goods/${id}`)
  },

  getTags: (id: string) => {
    return request.get<any, OriginGoodTagsResult>(`/origin-goods/${id}/tags`)
  },

  // 人工接管链接标签（全量替换，自动同步不再覆盖）
  updateTags: (id: string, tagIds: string[]) => {
    return request.put<any, OriginGoodTagsResult>(`/origin-goods/${id}/tags`, { tagIds: tagIds.map(Number) })
  },

  // 恢复自动派生（清掉人工标签）
  resetTags: (id: string) => {
    return request.delete<any, OriginGoodTagsResult>(`/origin-goods/${id}/tags`)
  },
}
