import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import type { Withdraw, WithdrawParam, AuditPassParam, AuditRejectParam } from './model';

/**
 * 分页查询收益明细
 */
export async function withdrawPage(params: WithdrawParam) {
  const res = await request.get<ApiResult<PageResult<Withdraw>>>(
    '/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 pass(params: AuditPassParam) {
  const res = await request.post<ApiResult<ApiResult>>(
    '/shop/merchant-withdraw/audit/pass', params
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function reject(params: AuditRejectParam) {
  const res = await request.post<ApiResult<ApiResult>>(
    '/shop/merchant-withdraw/audit/reject', params
  );
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
