import type { Pagination } from '@/types/global';
import qs from 'query-string';
import type { CommonResult } from './common';
import axios from 'axios';
import type {
  KamiApiCardInfoWalmartV1RedeemConfigGetRes,
  KamiApiCardInfoWalmartV1ListRes,
  KamiInternalModelEntityV1CardRedeemOrderHistory
} from './generated';

export interface walmartCardOrderRecord {
  /**
   * @description
   */
  id: number;

  /**
   * @description
   */
  orderNo: string;

  /**
   * @description
   */
  merchantId: string;

  /**
   * @description
   */
  attach: string;

  /**
   * @description
   */
  cookie: string;

  /**
   * @description
   */
  accountId: number;

  /**
   * @description
   */
  giftCardPwd: string;

  /**
   * @description 回调
   */
  notifyUrl: string;

  notifyStatus: number;

  /**
   * @description
   */
  amount: number;

  /**
   * @description 备注
   */
  remark: string;

  /**
   * @description 1.兑换成功 2.兑换失败
   */
  status: number;

  /**
   * @description
   */
  createdAt?: Date;

  /**
   * @description
   */
  updatedAt?: Date;

  /**
   * @description
   */
  deletedAt?: Date;
}

export interface walmartCardOrderParams
  extends Partial<walmartCardOrderRecord>,
    Pagination {
  dateRange?: string[];
  endDate?: Date | null;
  accountNickName?: string;
  groupId?: number | null;
}

// 获取充值列表
export function queryWalmartCardOrderList(params: walmartCardOrderParams) {
  return axios.get<KamiApiCardInfoWalmartV1ListRes>(
    '/api/cardInfo/walmart/order/list',
    {
      params,
      paramsSerializer: obj => {
        return qs.stringify(obj, { arrayFormat: 'bracket' });
      }
    }
  );
}

// 获取充值操作记录
export function queryWalmartOrderHistoryList(params: { orderNo: string }) {
  return axios.get<
    CommonResult<KamiInternalModelEntityV1CardRedeemOrderHistory>
  >('/api/cardInfo/walmart/order/getHistoryList', {
    params,
    paramsSerializer: obj => {
      return qs.stringify(obj);
    }
  });
}

export function getWalmartConfig() {
  return axios.get<Required<KamiApiCardInfoWalmartV1RedeemConfigGetRes>>(
    '/api/cardInfo/walmart/config/get'
  );
}
