import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  FlfFulfillerVO, FlfFulfillerForm, FlfFulfillerQuery,
  FlfFulfillerOnOrderVO, FlfFulfillerOnOrderQuery,
  FlfRewardForm, FlfAdjustPointsForm, FlfAdjustBalanceForm,
  FlfPointsLogVO, FlfBalanceLogVO, FlfRewardLogVO
} from './types';

/**
 * 查询履约者列表
 */
export const listFulfiller = (query?: FlfFulfillerQuery): AxiosPromise<FlfFulfillerVO[]> => {
  return request({
    url: '/fulfiller/fulfiller/list',
    method: 'get',
    params: query
  });
};

/**
 * 下单派单时查询履约者（分页）
 */
export const pageFulfillerOnOrder = (query?: FlfFulfillerOnOrderQuery): AxiosPromise<{ total: number; rows: FlfFulfillerOnOrderVO[] }> => {
  return request({
    url: '/fulfiller/fulfiller/pageOnOrder',
    method: 'get',
    params: query
  });
};

/**
 * 查询履约者详细
 */
export const getFulfiller = (id: string | number): AxiosPromise<FlfFulfillerVO> => {
  return request({
    url: '/fulfiller/fulfiller/' + id,
    method: 'get'
  });
};

/**
 * 新增履约者
 */
export const addFulfiller = (data: FlfFulfillerForm) => {
  return request({
    url: '/fulfiller/fulfiller',
    method: 'post',
    data: data
  });
};

/**
 * 修改履约者
 */
export const updateFulfiller = (data: FlfFulfillerForm) => {
  return request({
    url: '/fulfiller/fulfiller',
    method: 'put',
    data: data
  });
};

/**
 * 切换状态
 */
export const changeStatus = (id: string | number, status: string) => {
  return request({
    url: '/fulfiller/fulfiller/changeStatus',
    method: 'put',
    params: { id, status }
  });
};

/**
 * 重置密码
 */
export const resetPwd = (id: string | number, password: string) => {
  return request({
    url: '/fulfiller/fulfiller/resetPwd',
    method: 'put',
    params: { id, password }
  });
};

/**
 * 奖惩操作
 */
export const reward = (data: FlfRewardForm) => {
  return request({
    url: '/fulfiller/fulfiller/reward',
    method: 'post',
    data: data
  });
};

/**
 * 调整积分
 */
export const adjustPoints = (data: FlfAdjustPointsForm) => {
  return request({
    url: '/fulfiller/fulfiller/adjustPoints',
    method: 'post',
    data: data
  });
};

/**
 * 调整余额
 */
export const adjustBalance = (data: FlfAdjustBalanceForm) => {
  return request({
    url: '/fulfiller/fulfiller/adjustBalance',
    method: 'post',
    data: data
  });
};

/**
 * 查询积分日志
 */
export const listPointsLog = (fulfillerId: string | number, query?: PageQuery): AxiosPromise<FlfPointsLogVO[]> => {
  return request({
    url: '/fulfiller/log/points',
    method: 'get',
    params: { fulfillerId, ...query }
  });
};

/**
 * 查询余额日志
 */
export const listBalanceLog = (fulfillerId: string | number, query?: PageQuery): AxiosPromise<FlfBalanceLogVO[]> => {
  return request({
    url: '/fulfiller/log/balance',
    method: 'get',
    params: { fulfillerId, ...query }
  });
};

/**
 * 查询奖惩日志
 */
export const listRewardLog = (fulfillerId: string | number, query?: PageQuery): AxiosPromise<FlfRewardLogVO[]> => {
  return request({
    url: '/fulfiller/log/reward',
    method: 'get',
    params: { fulfillerId, ...query }
  });
};
