import type { ApiResponse } from "@/lib/api"
import { callByUser } from "./base"

export type CreateOrderRequest = {
  PackageId: number
  OrderType: number
  Account: string
  Pwd: string
  ConnectCount: number
  MinPostfix?: number
  MaxPostfix?: number
  CouponId?: number
  UseAccountAmount?: number
  OPayType: number
  PayChannel?: number
  Price?: number
}

export type CreateTestAccountRequest = {
  ProductId: number
  PackageId: number
  Account: string
  Pwd: string
}

export type OrderInfo = {
  OrderNo: string
  OtherPayAmount: number
  CreateTime: string
  PayType: number
}

export type CreateOrderData = {
  OrderInfo: OrderInfo
  PayData: string
}

export async function createOrder(
  data: CreateOrderRequest,
): Promise<ApiResponse<CreateOrderData | string>> {
  return await callByUser<CreateOrderData | string>(
    "/product/CreateOrder",
    data,
  )
}

export async function createTestAccount(
  data: CreateTestAccountRequest,
): Promise<ApiResponse<string>> {
  return await callByUser<string>(
    "/api/course/v1/productaccount/CreateTestAccount",
    data,
  )
}

export async function checkPayStatus(
  orderNo: string,
): Promise<ApiResponse<number>> {
  return await callByUser<number>(
    `/product/IsPay?orderNo=${orderNo}`,
    undefined,
    "GET",
  )
}
