/**
 * Generated by orval v7.6.0 🍺
 * Do not edit manually.
 * Coinbase Developer Platform APIs
 * The Coinbase Developer Platform APIs - leading the world's transition onchain.
 * OpenAPI spec version: 2.0.0
 */
import type {
  CreateEvmSmartAccountBody,
  CreateSpendPermissionRequest,
  EvmSmartAccount,
  EvmUserOperation,
  ListEvmSmartAccounts200,
  ListEvmSmartAccountsParams,
  ListSpendPermissions200,
  ListSpendPermissionsParams,
  PrepareUserOperationBody,
  RevokeSpendPermissionRequest,
  SendUserOperationBody,
  UpdateEvmSmartAccountBody,
} from "../coinbaseDeveloperPlatformAPIs.schemas.js";

import { cdpApiClient } from "../../cdpApiClient.js";

type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];

/**
 * Lists the Smart Accounts belonging to the developer's CDP Project.
The response is paginated, and by default, returns 20 accounts per page.
 * @summary List Smart Accounts
 */
export const listEvmSmartAccounts = (
  params?: ListEvmSmartAccountsParams,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<ListEvmSmartAccounts200>(
    { url: `/v2/evm/smart-accounts`, method: "GET", params },
    options,
  );
};
/**
 * Creates a new Smart Account.
 * @summary Create a Smart Account
 */
export const createEvmSmartAccount = (
  createEvmSmartAccountBody: CreateEvmSmartAccountBody,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmSmartAccount>(
    {
      url: `/v2/evm/smart-accounts`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: createEvmSmartAccountBody,
    },
    options,
  );
};
/**
 * Gets a Smart Account by its name.
 * @summary Get a Smart Account by name
 */
export const getEvmSmartAccountByName = (
  name: string,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmSmartAccount>(
    { url: `/v2/evm/smart-accounts/by-name/${name}`, method: "GET" },
    options,
  );
};
/**
 * Gets a Smart Account by its address.
 * @summary Get a Smart Account by address
 */
export const getEvmSmartAccount = (
  address: string,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmSmartAccount>(
    { url: `/v2/evm/smart-accounts/${address}`, method: "GET" },
    options,
  );
};
/**
 * Updates an existing EVM smart account. Use this to update the smart account's name.
 * @summary Update an EVM Smart Account
 */
export const updateEvmSmartAccount = (
  address: string,
  updateEvmSmartAccountBody: UpdateEvmSmartAccountBody,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmSmartAccount>(
    {
      url: `/v2/evm/smart-accounts/${address}`,
      method: "PUT",
      headers: { "Content-Type": "application/json" },
      data: updateEvmSmartAccountBody,
    },
    options,
  );
};
/**
 * Prepares a new user operation on a Smart Account for a specific network.
 * @summary Prepare a user operation
 */
export const prepareUserOperation = (
  address: string,
  prepareUserOperationBody: PrepareUserOperationBody,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmUserOperation>(
    {
      url: `/v2/evm/smart-accounts/${address}/user-operations`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: prepareUserOperationBody,
    },
    options,
  );
};
/**
 * Gets a user operation by its hash.
 * @summary Get a user operation
 */
export const getUserOperation = (
  address: string,
  userOpHash: string,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmUserOperation>(
    { url: `/v2/evm/smart-accounts/${address}/user-operations/${userOpHash}`, method: "GET" },
    options,
  );
};
/**
 * Sends a user operation with a signature.
The payload to sign must be the `userOpHash` field of the user operation. This hash should be signed directly (not using `personal_sign` or EIP-191 message hashing).
The signature must be 65 bytes in length, consisting of: - 32 bytes for the `r` value - 32 bytes for the `s` value - 1 byte for the `v` value (must be 27 or 28)
If using the CDP Paymaster, the user operation must be signed and sent within 2 minutes of being prepared.
 * @summary Send a user operation
 */
export const sendUserOperation = (
  address: string,
  userOpHash: string,
  sendUserOperationBody: SendUserOperationBody,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmUserOperation>(
    {
      url: `/v2/evm/smart-accounts/${address}/user-operations/${userOpHash}/send`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: sendUserOperationBody,
    },
    options,
  );
};
/**
 * Creates a spend permission for the given smart account address.
 * @summary Create a spend permission
 */
export const createSpendPermission = (
  address: string,
  createSpendPermissionRequest: CreateSpendPermissionRequest,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmUserOperation>(
    {
      url: `/v2/evm/smart-accounts/${address}/spend-permissions`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: createSpendPermissionRequest,
    },
    options,
  );
};
/**
 * Lists spend permission for the given smart account address.
 * @summary List spend permissions
 */
export const listSpendPermissions = (
  address: string,
  params?: ListSpendPermissionsParams,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<ListSpendPermissions200>(
    { url: `/v2/evm/smart-accounts/${address}/spend-permissions/list`, method: "GET", params },
    options,
  );
};
/**
 * Revokes an existing spend permission.
 * @summary Revoke a spend permission
 */
export const revokeSpendPermission = (
  address: string,
  revokeSpendPermissionRequest: RevokeSpendPermissionRequest,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<EvmUserOperation>(
    {
      url: `/v2/evm/smart-accounts/${address}/spend-permissions/revoke`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: revokeSpendPermissionRequest,
    },
    options,
  );
};
export type ListEvmSmartAccountsResult = NonNullable<
  Awaited<ReturnType<typeof listEvmSmartAccounts>>
>;
export type CreateEvmSmartAccountResult = NonNullable<
  Awaited<ReturnType<typeof createEvmSmartAccount>>
>;
export type GetEvmSmartAccountByNameResult = NonNullable<
  Awaited<ReturnType<typeof getEvmSmartAccountByName>>
>;
export type GetEvmSmartAccountResult = NonNullable<Awaited<ReturnType<typeof getEvmSmartAccount>>>;
export type UpdateEvmSmartAccountResult = NonNullable<
  Awaited<ReturnType<typeof updateEvmSmartAccount>>
>;
export type PrepareUserOperationResult = NonNullable<
  Awaited<ReturnType<typeof prepareUserOperation>>
>;
export type GetUserOperationResult = NonNullable<Awaited<ReturnType<typeof getUserOperation>>>;
export type SendUserOperationResult = NonNullable<Awaited<ReturnType<typeof sendUserOperation>>>;
export type CreateSpendPermissionResult = NonNullable<
  Awaited<ReturnType<typeof createSpendPermission>>
>;
export type ListSpendPermissionsResult = NonNullable<
  Awaited<ReturnType<typeof listSpendPermissions>>
>;
export type RevokeSpendPermissionResult = NonNullable<
  Awaited<ReturnType<typeof revokeSpendPermission>>
>;
