import type { Treaty } from "@elysiajs/eden";
import type { client } from ".";
import type { AssetCodeEnum, WithdrawMethodEnum } from "./enum";
import type { authClient } from "@/auth";

export type TreatyQuery<T> = T extends (...args: any[]) => any
  ? NonNullable<NonNullable<Parameters<T>[0]>["query"]>
  : never;

export type TreatyBody<T> = T extends (...args: any[]) => any
  ? NonNullable<Parameters<T>[0]>
  : never;

export type DepositFiatData = Treaty.Data<typeof client.api.deposit.fiat.post>;

export type BalancesData = Treaty.Data<typeof client.api.wallet.balances.get>;

export type TotalAssetValue = Treaty.Data<typeof client.api.wallet.total_value.get>;

export type WithdrawBody = Omit<Parameters<typeof client.api.withdraw.post>[0], "assetCode" | "withdrawMethod"> & {
  assetCode: AssetCodeEnum;
  withdrawMethod: WithdrawMethodEnum;
};

export type DepositFiatBody = TreatyBody<typeof client.api.deposit.fiat.post>;

export type UserProfileData = Treaty.Data<typeof client.api.user.profile.get>;

export type UpdateUserProfileBody = TreatyBody<typeof client.api.user.profile.put>;

export type RwaIssuanceProductsData = Treaty.Data<typeof client.api.rwa.issuance.products.bundle.post>;

export type RwaIssuanceProductBody = TreatyBody<typeof client.api.rwa.issuance.products.bundle.post>;

export type RwaIssuanceCategoriesData = Treaty.Data<typeof client.api.rwa.category.categories.get>;

export type BankAccountsData = Treaty.Data<typeof client.api.bank_account.get>;

export type BankAccountBody = TreatyBody<typeof client.api.bank_account.post>;

export type BankAccountData = Treaty.Data<typeof client.api.bank_account.post>;

export type SupportBanksData = Treaty.Data<typeof client.api.bank_account.banks.get>;

export type AvailableSubscriptionBody = TreatyQuery<typeof client.api.rwa.subscription.available_editions.get>;

export type RwaData = Treaty.Data<typeof client.api.rwa.subscription.available_editions.get>["data"][number];

export type MyIssueRwaData = Treaty.Data<typeof client.api.rwa.issuance.products.get>["data"][number];

export type MySubscribeRwaData = Treaty.Data<typeof client.api.rwa.subscription.my_subscriptions.get>["data"][number];

export type MySubscribeRwaBody = TreatyQuery<typeof client.api.rwa.subscription.my_subscriptions.get>;

export type PhoneNumberVerifyClient = TreatyBody<typeof authClient.phoneNumber.verify>;

export type UsernameClient = TreatyBody<typeof authClient.signIn.username>;

export type EmailVerifyClient = TreatyBody<typeof authClient.emailOtp.verifyEmail>;

export type UserDepositOrderData = Treaty.Data<typeof client.api.deposit.orders.get>["data"][number];

export type UserDepositOrderBody = TreatyQuery<typeof client.api.deposit.orders.get>;

export type UserWithdrawOrderData = Treaty.Data<typeof client.api.withdraw.get>["data"][number];

export type UserWithdrawOrderBody = TreatyQuery<typeof client.api.withdraw.get>;

export type MarketDataStreaming = ReturnType<typeof client.api.market_data.streaming.subscribe>;

export type AssetRecordBody = TreatyQuery<typeof client.api.ledger.entries.get>;

export type AssetRecordData = Treaty.Data<typeof client.api.ledger.entries.get>["data"][number];

export type TradableData = Treaty.Data<typeof client.api.rwa.tokenization.tradable_products.get>["data"][number];

export type TradableBody = TreatyQuery<typeof client.api.rwa.tokenization.tradable_products.get>;

/**
 * 应用版本信息
 */
export interface VersionInfo {
  /** 最新版本号，如 "1.2.3" */
  version: string;
  /** 构建号 */
  buildNumber?: number;
  /** 是否强制更新 */
  forceUpdate: boolean;
  /** 更新提示信息 */
  updateMessage?: string;
  /** 更新下载链接（App Store / Google Play） */
  updateUrl?: string;
  /** 最低支持版本，低于此版本必须更新 */
  minSupportVersion?: string;
  /** 发布时间 */
  releaseDate?: string;
  /** 更新内容 */
  releaseNotes?: string[];
}
