import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { PtUserAccountVO, PtUserAccountForm, PtUserAccountQuery } from '@/api/payment/account/types';
import { DeptVO } from '@/api/system/dept/types';
import { UserVO } from '@/api/system/user/types';
import { PtCardVO } from '@/api/cardCenter/cardOperation/ptCard/types';
import { PtBagVO } from '@/api/payment/bag/types';

/**
 * 查询一卡通账户列表
 * @param query
 * @returns {*}
 */
export const listPtUserAccount = (query?: PtUserAccountQuery): AxiosPromise<PtUserAccountVO[]> => {
  return request({
    url: '/backstage/payment/ptUserAccount/list',
    method: 'get',
    params: query
  });
};

export const listPtUserAccount4Select = (query?: PtUserAccountQuery): AxiosPromise<PtUserAccountVO[]> => {
  return request({
    url: '/backstage/payment/ptUserAccount/list4Select',
    method: 'get',
    params: query
  });
};

/**
 * 查询一卡通账户详细
 * @param userId
 */
export const getPtUserAccount = (userId: string | number): AxiosPromise<PtUserAccountVO> => {
  return request({
    url: '/backstage/payment/ptUserAccount/' + userId,
    method: 'get'
  });
};

/**
 * 新增一卡通账户
 * @param data
 */
export const addPtUserAccount = (data: PtUserAccountForm) => {
  return request({
    url: '/backstage/payment/ptUserAccount',
    method: 'post',
    data: data
  });
};

/**
 * 修改一卡通账户
 * @param data
 */
export const updatePtUserAccount = (data: PtUserAccountForm) => {
  return request({
    url: '/backstage/payment/ptUserAccount',
    method: 'put',
    data: data
  });
};

/**
 * 删除一卡通账户
 * @param userId
 */
export const delPtUserAccount = (userId: string | number | Array<string | number>) => {
  return request({
    url: '/backstage/payment/ptUserAccount/' + userId,
    method: 'delete'
  });
};

/**
 * 查询部门下拉树结构
 */
export const deptTreeSelect = (): AxiosPromise<DeptVO[]> => {
  return request({
    url: '/backstage/payment/ptUserAccount/deptTree',
    method: 'get'
  });
};

/**
 * 查询账户卡片
 * @param userId 用户ID
 */
export const getAccountCard = (userId: string | number): AxiosPromise<{ account: PtUserAccountVO; cards: PtCardVO[] }> => {
  return request({
    url: '/backstage/payment/ptUserAccount/accountCard/' + userId,
    method: 'get'
  });
};

/**
 * 查询账户钱包
 * @param userId 用户ID
 */
export const getAccountBag = (userId: string | number): AxiosPromise<{ account: PtUserAccountVO; bags: PtBagVO[] }> => {
  return request({
    url: '/backstage/payment/ptUserAccount/accountBag/' + userId,
    method: 'get'
  });
};

/**
 * 更改账户冻结状态
 * @param userId
 * @param status
 */
export const changeFreezeStatus = (userId: string | number | Array<string | number>, status: string) => {
  return request({
    url: '/backstage/payment/ptUserAccount/' + status + '/' + userId,
    method: 'put'
  });
};
/**
 * 重置账户有效期
 * @param userId
 * @param lifespan
 */
export const resetLifespan = (userId: string | number | Array<string | number>, lifespan: string) => {
  return request({
    url: '/backstage/payment/ptUserAccount/resetLifespan/' + lifespan + '/' + userId,
    method: 'put'
  });
};
/**
 * 重置账户卡类
 * @param userId
 * @param cardType
 */
export const resetCardType = (userId: string | number | Array<string | number>, cardType: string) => {
  return request({
    url: '/backstage/payment/ptUserAccount/resetCardType/' + cardType + '/' + userId,
    method: 'put'
  });
};
/**
 * 重置账户消费密码
 * @param userId
 * @param consumePwd
 */
export const resetConsumePwd = (userId: string | number | Array<string | number>, consumePwd: string) => {
  return request({
    url: '/backstage/payment/ptUserAccount/resetConsumePwd/' + consumePwd + '/' + userId,
    method: 'put'
  });
};
/**
 * 开户
 * @param userId
 */
export const openAccount = (userId: string | number | Array<string | number>) => {
  return request({
    url: '/backstage/payment/ptUserAccount/open/' + userId,
    method: 'put'
  });
};
/**
 * 销户
 * @param userId
 */
export const closeAccount = (userId: string | number | Array<string | number>) => {
  return request({
    url: '/backstage/payment/ptUserAccount/close/' + userId,
    method: 'put'
  });
};

export const photoBatchUpload = (data) => {
  return request({
    url: '/backstage/payment/ptUserAccount/photoBatchUpload',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
};

export default {
  listPtUserAccount,
  listPtUserAccount4Select,
  getPtUserAccount,
  addPtUserAccount,
  updatePtUserAccount,
  delPtUserAccount,
  deptTreeSelect,
  getAccountCard,
  getAccountBag,
  changeFreezeStatus,
  resetLifespan,
  resetCardType,
  resetConsumePwd,
  openAccount,
  closeAccount,
  photoBatchUpload
};
