import request from '@/utils/request'

// 分页列表（一页10条）
export function listUserEndCategory(query) {
  return request({
    url: '/store/store/userEndCategory/list',
    method: 'get',
    params: query
  })
}

// 添加/编辑商品时拉取用户端分类（金刚区、瀑布流）
export function listUserEndCategoryForProduct(storeId) {
  return request({
    url: '/store/store/userEndCategory/listForProduct',
    method: 'get',
    params: { storeId }
  })
}

export function getUserEndCategory(id) {
  return request({
    url: '/store/store/userEndCategory/' + id,
    method: 'get'
  })
}

export function addUserEndCategory(data) {
  return request({
    url: '/store/store/userEndCategory',
    method: 'post',
    data
  })
}

export function updateUserEndCategory(data) {
  return request({
    url: '/store/store/userEndCategory',
    method: 'put',
    data
  })
}

export function delUserEndCategory(ids) {
  return request({
    url: '/store/store/userEndCategory/' + ids,
    method: 'delete'
  })
}

// 按用户端分类ID分页查询关联商品（商品ID、名称、售价、原价、销量、产品标签）
export function listCategoryProducts(id, params) {
  return request({
    url: '/store/store/userEndCategory/products',
    method: 'get',
    params: { id, ...params }
  })
}

/** 批量保存关联排序（当前页商品 productId + sort，id 为用户分端类 ID） */
export function saveCategoryProductsSort(id, items) {
  return request({
    url: '/store/store/userEndCategory/products/sort',
    method: 'put',
    params: { id },
    data: items
  })
}
