import request from '@/utils/request'
import { sellerShopHeaders } from '@/utils/sellerShop'

// 查询当前店铺商品列表
export function listSellerGoods(query) {
  return request({
    url: '/agri/seller/goods/list',
    method: 'get',
    params: query,
    headers: sellerShopHeaders()
  })
}

// 平台二级「商品分类」下拉
export function sellerGoodsCategoryOptions() {
  return request({
    url: '/agri/seller/goods/categoryOptions',
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 本店二级「店铺商品分类」下拉
export function sellerGoodsShopCategoryOptions(visibleOnly) {
  return request({
    url: '/agri/seller/goods/shopCategoryOptions',
    method: 'get',
    params: { visibleOnly: visibleOnly },
    headers: sellerShopHeaders()
  })
}

// 商品服务选项（all + defaultShow）
export function sellerGoodsServiceOptions() {
  return request({
    url: '/agri/seller/goods/serviceOptions',
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 本店属性模版下拉
export function sellerAttrTemplateOptions() {
  return request({
    url: '/agri/seller/goods/attrTemplateOptions',
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 选用属性模版预填 attributes / specs
export function getSellerAttrTemplateDetail(templateId) {
  return request({
    url: '/agri/seller/goods/attrTemplate/' + templateId,
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 本店运费模版下拉
export function sellerFreightTemplateOptions() {
  return request({
    url: '/agri/seller/goods/freightTemplateOptions',
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 默认运费模版预填
export function getSellerFreightDefault() {
  return request({
    url: '/agri/seller/goods/freightDefault',
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 选用运费模版详情回显
export function getSellerFreightTemplateDetail(templateId) {
  return request({
    url: '/agri/seller/goods/freightTemplate/' + templateId,
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 查询商品详情
export function getSellerGoods(goodsId) {
  return request({
    url: '/agri/seller/goods/' + goodsId,
    method: 'get',
    headers: sellerShopHeaders()
  })
}

// 新增商品
export function addSellerGoods(data) {
  return request({
    url: '/agri/seller/goods',
    method: 'post',
    data: data,
    headers: sellerShopHeaders()
  })
}

// 修改商品
export function updateSellerGoods(data) {
  return request({
    url: '/agri/seller/goods',
    method: 'put',
    data: data,
    headers: sellerShopHeaders()
  })
}

// 提交上架（单条）
export function submitSellerGoods(goodsId) {
  return request({
    url: '/agri/seller/goods/' + goodsId + '/submit',
    method: 'put',
    headers: sellerShopHeaders()
  })
}

// 批量提交上架
export function submitSellerGoodsBatch(data) {
  return request({
    url: '/agri/seller/goods/submit',
    method: 'put',
    data: data,
    headers: sellerShopHeaders()
  })
}

// 下架（单条）
export function offShelfSellerGoods(goodsId) {
  return request({
    url: '/agri/seller/goods/' + goodsId + '/offShelf',
    method: 'put',
    headers: sellerShopHeaders()
  })
}

// 批量下架
export function offShelfSellerGoodsBatch(data) {
  return request({
    url: '/agri/seller/goods/offShelf',
    method: 'put',
    data: data,
    headers: sellerShopHeaders()
  })
}

// 删除商品（支持批量，逗号分隔 ID）
export function delSellerGoods(goodsIds) {
  return request({
    url: '/agri/seller/goods/' + goodsIds,
    method: 'delete',
    headers: sellerShopHeaders()
  })
}
