import type { PageConfig, ProductEntity } from '@vben/types';

import { parseQueryValues } from '@vben/utils';

import { requestClient } from '#/api/request';

interface ProductPartialEntity
  extends Partial<Omit<ProductEntity, 'productsname'>> {
  productsname?: string;
}

interface ProductQueryParams extends PageConfig, ProductPartialEntity {}

/**
 * 产品信息_列表
 */
export async function getProductListApi(params: ProductQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=23', {
    ...params,
    'productsmerchantid.like': params.productsmerchantid || '',
  });
}

/**
 * 产品_生产企业_视图列表
 */
export async function getProductAndScqyListApi(params: ProductQueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=121', {
    ...params,
    'productsmerchantid.like': params.productsmerchantid || '',
    'scqyinfomc.like': params.scqyinfomc || '',
    'productscategory.like': params.productscategory || '',
    'productsjjlx.like': params.productsjjlx || '',
    'productsmodel.like': params.productsmodel || '',
    'productsname.like': params.productsname || '',
  });
}

/**
 * 产品信息_详情
 */
export async function getProductDetailApi(data: { productsid: string }) {
  return requestClient.post<any>(
    '/api/query/view?pagevalue=24',
    {
      ...parseQueryValues(data),
    },
    { formatData: true }, // 格式化返回数据
  );
}

/**
 * 产品信息_新增
 */
export async function addProductApi(data: ProductEntity) {
  return requestClient.post<any>('/api/add?pagevalue=25', { ...data });
}

/**
 * 产品信息_编辑
 */
export async function editProductApi(
  data: ProductPartialEntity & { productsid: string },
) {
  return requestClient.post<any>('/api/up?pagevalue=26', { ...data });
}

/**
 * 产品信息_删除
 */
export async function deleteProductApi(data: { 'productsid.value': string }) {
  return requestClient.post<any>('/api/del?pagevalue=27', { ...data });
}
