import http from '@/utils/http'
import { AppDispatch } from '@/store'

/**
 * 藏品总账-获取藏品详情
 */
export const API_getGoodsInfo = (id: number) => {
  return http.get(`cms/good/ledger/detail/${id}`)
}

/**
 * 藏品总账-获取藏品分页列表
 */
export const API_getGoodsList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post(`cms/good/ledger/page`, data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

      dispatch({ type: 'C1/getList', payload: obj })
    }
  }
}

/**
 * 藏品总账-获取藏品列表
 */
export const API_getGoodsLists = (data: any): any => {
  return http.post(`cms/good/ledger/page`, data)
}

/**
 * 藏品-附件-根据藏品Id查询
 */
type GetGoodsByGoodIdReq = {
  moduleId: number
  moduleName: string
  type: string
}
export const API_getGoodsByGoodId = (data: GetGoodsByGoodIdReq) => {
  return http.post(`cms/good/ledger/file`, data)
}

// ----------------故事模块-----------
/**
 * 故事-新增
 */
export const guShiAPI_add = (data: any) => {
  return http.post('cms/story/save', data)
}
/**
 * 故事-获取列表（完整）
 */
export const guShiAPI_getList = (goodId: number) => {
  const data: any = {
    goodId,
    pageSize: 99999
  }
  return http.post('cms/good/ledger/story', data)
}
/**
 * 故事-详情
 */
export const guShiAPI_getInfo = (id: number) => {
  return http.get(`cms/story/detail/${id}`)
}

/**
 * 故事-删除
 */
export const guShiAPI_dels = (ids: number[]) => {
  return http.post(`cms/story/removes`, ids)
}
