import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { BaseVO, BaseForm, BaseQuery, StatusCountVo } from '@/api/product/base/types';
import { CategoryQuery, categoryTreeVO, CategoryVO } from '../category/types';
import { BrandQuery, BrandVO } from '../brand/types';
import { AttributesVO } from '../attributes/types';
import { EnsureQuery, EnsureVO } from '../ensure/types';
import { AfterSalesQuery, AfterSalesVO } from '../afterSales/types';
import { UnitQuery, UnitVO } from '../unit/types';

/**
 * 查询产品基础信息列表
 * @param query
 * @returns {*}
 */

export const listBase = (query?: BaseQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/base/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品基础信息详细
 * @param id
 */
export const getBase = (id: string | number): AxiosPromise<BaseVO> => {
  return request({
    url: '/product/base/' + id,
    method: 'get'
  });
};

/**
 * 新增产品基础信息
 * @param data
 */
export const addBase = (data: BaseForm) => {
  return request({
    url: '/product/base',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品基础信息
 * @param data
 */
export const updateBase = (data: BaseForm) => {
  return request({
    url: '/product/base',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品基础信息
 * @param id
 */
export const delBase = (id: string | number | Array<string | number>) => {
  return request({
    url: '/product/base/' + id,
    method: 'delete'
  });
};

/**
 * 获取产品分类树
 * @param query
 * @returns {*}
 */
export const categoryTree = (query?: CategoryQuery): AxiosPromise<categoryTreeVO[]> => {
  return request({
    url: '/product/base/categoryTree',
    method: 'get',
    params: query
  });
};
/**
 * 查询产品分类信息列表
 * @param query
 * @returns {*}
 */
export const categoryList = (query?: CategoryQuery): AxiosPromise<CategoryVO[]> => {
  return request({
    url: '/product/base/categoryList',
    method: 'get',
    params: query
  });
};
/**
 * 查询产品品牌信息列表
 * @param query
 * @returns {*}
 */
export const brandList = (query?: BrandQuery): AxiosPromise<BrandVO[]> => {
  return request({
    url: '/product/base/brandList',
    method: 'get',
    params: query
  });
};
/**
 * 查询产品分类下的属性列表
 * @param id
 * @returns {*}
 */
export const categoryAttributeList = (id: string | number): AxiosPromise<AttributesVO[]> => {
  return request({
    url: '/product/base/getProductAttributeList/' + id,
    method: 'get'
  });
};

/**
 * 查询产品服务保障列表
 * @param query
 * @returns {*}
 */
export const getServiceList = (query?: EnsureQuery): AxiosPromise<EnsureVO[]> => {
  return request({
    url: '/product/base/getServiceList',
    method: 'get',
    params: query
  });
};

/**
 * 获取售后服务信息列表
 * @param query
 * @returns {*}
 */
export const getAfterSaleList = (query?: AfterSalesQuery): AxiosPromise<AfterSalesVO[]> => {
  return request({
    url: '/product/base/getAfterSalesList',
    method: 'get',
    params: query
  });
};

/**
 * 获取单位信息列表
 * @param query
 * @returns {*}
 */
export const getUnitList = (query?: UnitQuery): AxiosPromise<UnitVO[]> => {
  return request({
    url: '/product/base/getUnitList',
    method: 'get',
    params: query
  });
};

/**
 * 商品审核
 * @param data 审核信息（包含id、productReviewStatus、reviewComments）
 */
export const reviewBase = (data: BaseForm) => {
  return request({
    url: '/product/base/review',
    method: 'post',
    data: data
  });
};

/**
 * 商品上下架审核
 * @param data 审核信息（包含id、productStatus、shelfComments）
 */
export const shelfReview = (data: BaseForm) => {
  return request({
    url: '/product/base/shelfReview',
    method: 'post',
    data: data
  });
};
/**
 * 获取所有商品各个状态数量
 */
export const getProductStatusCount = (): AxiosPromise<StatusCountVo> => {
  return request({
    url: '/product/base/getProductStatusCount',
    method: 'get'
  });
};
/**
 * 商品类型改变  1=默认类型,2精选商品,3=停售商品
 * @param data 停售信息（包含id、productStatus、shelfComments）
 */
export const changeProductType = (data: BaseForm) => {
  return request({
    url: '/product/base/changeProductType',
    method: 'post',
    data: data
  });
};

/**
 * 获取税率列表
 */
export const getTaxRateList = () => {
  return request({
    url: '/system/taxrate/list',
    method: 'get'
  });
};

/**
 * 获取自营商品列表
 * */
export const getSelfProductPage = (query?: BaseQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/base/getSelfProductPage',
    method: 'get',
    params: query
  });
};

/**
 * 获取精品商品列表
 * */
export const getGoodProductPage = (query?: BaseQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/base/getGoodProductPage',
    method: 'get',
    params: query
  });
};

/**
 * 获取项目商品列表
 * */
export const getProjectProductPage = (query?: BaseQuery): AxiosPromise<BaseVO[]> => {
  return request({
    url: '/product/base/getItemProductPage',
    method: 'get',
    params: query
  });
};
