import { customerFetch, ResponseDataEntity } from './index';
import Order from '@/types/Order/Order';

export class Params {
  /** 会员id */
  customerId: number;
  /** 订单状态 1未支付 2已支付 为空时查询的全部 */
  orderState?: string;
  /** 最后一页最后一条订单ID */
  lastOrderId?: number;
  /** 每页条数 */
  pageSize?: number;
}

export const fetchAllOrder = (params: Params) =>
  customerFetch({
    url: '/consumeOrder/pageAllList',
    data: params,
  });

export const fetchPayOrder = (params: Params) =>
  customerFetch({
    url: '/consumeOrder/pageList',
    data: {
      ...params,
      orderState: 1,
    },
  });

type DetailParams = {
  id: number;
};
export const fetchOrderDetail = (data: DetailParams) =>
  customerFetch({
    url: '/consumeOrder/getDetail',
    data: data,
  });

export const fetchOrderDetailAndPay = (data: DetailParams) =>
  customerFetch({
    url: '/consumeOrder/getOrderDetailAndPay',
    data: data,
  });

type DeductionParams = {
  orderId: number;
  payType: string;
  paymentConfId: number;
};
export const fetchDeductionInfo = (data: DeductionParams) =>
  customerFetch({
    url: '/consumeOrder/getDeductionInfo',
    data: data,
  });

type ConfirmpayParams = {
  orderId: number;
  payType: string;
  activeId?: number;
  callType: string;
  paymentConfId: number;
  returnUrl: string;
  [propName: string]: any;
};
export const confirmPay = (data: ConfirmpayParams) =>
  customerFetch({
    url: '/consumeOrder/confirmPay',
    data: { ...data, appId: 'wxf2cac8f84183c8fc' },
  });

type RechargeParams = {
  customerId: number;
  lastOrderId?: number;
  pageSize?: number;
};

export type RechargeOrder = {
  /** 充值金额 */
  actualAmount: number;

  /** 充值后金额 */
  afterAmount?: number;

  /** 区域id */
  areaId: number;

  /** 区域名称 */
  areaName: string;

  /** 充值前金额 */
  beforeAmount?: number;

  /** 业务类型 APP充值=01  后台充值=02 后台退款=03 割接数据=04 后台平账记录=05 */
  businessType?: string;

  /** 订单完成时间 */
  completeAt?: string;

  /** 充值时间 */
  createAt?: string;

  /** 会员帐号 */
  customerId: number;

  /** 会员名称 */
  customerName: string;

  /** 会员手机 */
  customerPhone: string;

  /** 失败原因 */
  failReason?: string;

  /** 充值赠送豆数量 */
  giveMoney?: number;

  /** 操作人 */
  handler?: string;

  /** 主键id */
  id: number;

  /** 操作类型 1入账 2出账 */
  operType?: string;

  /** 运营商Id */
  operateId: number;

  /** 运营商名称 */
  operateName: string;

  /** 订单号 (xx：线下,wx：微信支付,zfb：支付宝)+年月日时分秒随机数5位 */
  orderNum: string;

  /** 订单状态(1:waitingPay待付款、2:paying支付中、3:success支付成功、4:failure支付失败 */
  orderState?: string;

  /** 支付类型(1:线下支付 2：微信支付 3 ：支付宝支付 4:京东支付 5:招行一网通支付 6:艾米币 7:专用豆 8通用豆) */
  payType?: string;

  rechargeRemark: string;

  /** 充值赠送服务id */
  serviceId?: number;

  /** 充值赠送服务名称 */
  serviceName?: string;

  /** 更新时间 */
  updateAt?: string;
};

export type RechargeOrderItem = {
  data: RechargeOrder[];
  groupName: string;
  sortNum: number;
};

export const fetchRechargeOrders = (
  data: RechargeParams,
): Promise<ResponseDataEntity<RechargeOrderItem[]>> =>
  customerFetch({
    url: '/dcxy/app/rechargeOrder/pageAllListRecharge',
    data,
  });
