import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { ShopDealerRecord, ShopDealerRecordParam } from './model';

/**
 * 分页查询客户跟进情况
 */
export async function pageShopDealerRecord(params: ShopDealerRecordParam) {
  const res = await request.get<ApiResult<PageResult<ShopDealerRecord>>>(
    '/shop/shop-dealer-record/page',
    {
      params
    }
  );
  if (res.code === 0) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 查询客户跟进情况列表
 */
export async function listShopDealerRecord(params?: ShopDealerRecordParam) {
  const res = await request.get<ApiResult<ShopDealerRecord[]>>(
    '/shop/shop-dealer-record',
    {
      params
    }
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 添加客户跟进情况
 */
export async function addShopDealerRecord(data: ShopDealerRecord) {
  const res = await request.post<ApiResult<unknown>>(
    '/shop/shop-dealer-record',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 修改客户跟进情况
 */
export async function updateShopDealerRecord(data: ShopDealerRecord) {
  const res = await request.put<ApiResult<unknown>>(
    '/shop/shop-dealer-record',
    data
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 删除客户跟进情况
 */
export async function removeShopDealerRecord(id?: number) {
  const res = await request.del<ApiResult<unknown>>(
    '/shop/shop-dealer-record/' + id
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 批量删除客户跟进情况
 */
export async function removeBatchShopDealerRecord(data: (number | undefined)[]) {
  const res = await request.del<ApiResult<unknown>>(
    '/shop/shop-dealer-record/batch',
    {
      data
    }
  );
  if (res.code === 0) {
    return res.message;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据id查询客户跟进情况
 */
export async function getShopDealerRecord(id: number) {
  const res = await request.get<ApiResult<ShopDealerRecord>>(
    '/shop/shop-dealer-record/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
