import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type {
  MerchantWithdraw,
  MerchantWithdrawParam
} from '@/api/love/withdraw/model';
/**
 * 分页查询日志
 */
export async function pageMerchantWithdraw(params: MerchantWithdrawParam) {
  const res = await request.get<ApiResult<PageResult<MerchantWithdraw>>>(
    '/shop/merchant-withdraw/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询日志列表
 */
export async function listMerchantWithdraw(params?: MerchantWithdrawParam) {
  const res = await request.get<ApiResult<MerchantWithdraw[]>>(
    '/shop/merchant-withdraw',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加日志
 */
export async function addMerchantWithdraw(data: MerchantWithdraw) {
  const res = await request.post<ApiResult<unknown>>(
    '/shop/merchant-withdraw',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改日志
 */
export async function updateMerchantWithdraw(data: MerchantWithdraw) {
  const res = await request.put<ApiResult<unknown>>(
    '/shop/merchant-withdraw',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 绑定日志
 */
export async function bindMerchantWithdraw(data: MerchantWithdraw) {
  const res = await request.put<ApiResult<unknown>>(
    '/shop/merchant-withdraw/bind',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量添加
 */
export async function addBatchMerchantWithdraw(data: MerchantWithdraw[]) {
  const res = await request.post<ApiResult<unknown>>(
    '/shop/merchant-withdraw/batch',
    data
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除日志
 */
export async function removeMerchantWithdraw(id?: number) {
  const res = await request.delete<ApiResult<unknown>>(
    '/shop/merchant-withdraw/' + id
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 批量删除日志
 */
export async function removeBatchMerchantWithdraw(
  data: (number | undefined)[]
) {
  const res = await request.delete<ApiResult<unknown>>(
    '/shop/merchant-withdraw/batch',
    {
      data
    }
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
