import type { Pagination } from '@/types/global';
import axios from 'axios';
import qs from 'query-string';
import type { CommonPageResult, CommonStrIdParams } from './common';

export interface TMallAccountRecord {
  accountNumber: string;
}

export interface TMallAccountParams
  extends Pagination,
    Partial<TMallAccountRecord> {}

export interface TMallAccountAddRecord extends CommonStrIdParams {
  status: string;
  totalDeposits: number;
  balance: number;
}

export function queryTMallAccountList(params: TMallAccountParams) {
  return axios.get<CommonPageResult<TMallAccountRecord>>(
    '/api/recharge/tMallGame/account/list',
    {
      params,
      paramsSerializer: obj => {
        return qs.stringify(obj);
      }
    }
  );
}

export function deleteTMallAccountItem(params: CommonStrIdParams) {
  return axios.delete('/api/recharge/tMallGame/account/delete', { params });
}

export function stopTMallAccountItem(data: CommonStrIdParams) {
  return axios.post('/api/recharge/tMallGame/account/toggle', data);
}

export function getTMallAuthorizeAppKey() {
  return axios.get<{ code: string; redirectUri: string }>(
    '/api/recharge/tMallGame/account/auth/getAuthorizeKey'
  );
}

export interface addRandomAccountParams {
  count: number;
}

export function addRandomAccountList(data: addRandomAccountParams) {
  return axios.post('/api/recharge/tMallGame/account/create', data);
}

export function checkTMallAuthStatus() {
  return axios.get<{ status: boolean; expiredAt: string }>(
    '/api/recharge/tMallGame/account/auth/getTMallAuthStatus'
  );
}

export function authorizeTMAllGameLogin(data: {
  code: string;
  channel: string;
}) {
  return axios.post('/api/recharge/tMallGame/account/auth/callback', data);
}

export interface TMallAccountDetailRecord {
  id: string;
  status: string;
  amount: string;
  createdAt: string;
  notes: string;
}

export interface TMallAccountDetailParams
  extends Pagination,
    Partial<TMallAccountDetailRecord> {
  id: string;
}

export function queryTMallAccountDetailList(params: TMallAccountDetailParams) {
  return axios.get<CommonPageResult<TMallAccountDetailRecord>>(
    '/api/recharge/tMallGame/account/list',
    {
      params,
      paramsSerializer: obj => {
        return qs.stringify(obj);
      }
    }
  );
}
