/**
 * Generated by orval v7.21.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 {
  AddEndUserEvmAccount201,
  AddEndUserEvmAccountBody,
  AddEndUserEvmSmartAccount201,
  AddEndUserEvmSmartAccountBody,
  AddEndUserSolanaAccount201,
  AddEndUserSolanaAccountBody,
  CreateEndUserBody,
  EndUser,
  ImportEndUserBody,
  ListEndUsers200,
  ListEndUsersParams,
  LookupEndUser200,
  LookupEndUserParams,
  ValidateEndUserAccessTokenBody,
} from "../coinbaseDeveloperPlatformAPIs.schemas.js";

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

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

/**
 * Creates an end user. An end user is an entity that can own CDP EVM accounts, EVM smart accounts, and/or Solana accounts. 1 or more authentication methods must be associated with an end user. By default, no accounts are created unless the optional `evmAccount` and/or `solanaAccount` fields are provided.
This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Create end user
 */
export const createEndUser = (
  createEndUserBody: CreateEndUserBody,
  options?: SecondParameter<typeof cdpApiClient<EndUser>>,
) => {
  return cdpApiClient<EndUser>(
    {
      url: `/v2/end-users`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: createEndUserBody,
    },
    options,
  );
};
/**
 * Lists the end users belonging to the developer's CDP Project.
By default, the response is sorted by creation date in ascending order and paginated to 20 users per page.
 * @summary List end users
 */
export const listEndUsers = (
  params?: ListEndUsersParams,
  options?: SecondParameter<typeof cdpApiClient<ListEndUsers200>>,
) => {
  return cdpApiClient<ListEndUsers200>({ url: `/v2/end-users`, method: "GET", params }, options);
};
/**
 * Validates the end user's access token and returns the end user's information. Returns an error if the access token is invalid or expired.

This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Validate end user access token
 */
export const validateEndUserAccessToken = (
  validateEndUserAccessTokenBody: ValidateEndUserAccessTokenBody,
  options?: SecondParameter<typeof cdpApiClient<EndUser>>,
) => {
  return cdpApiClient<EndUser>(
    {
      url: `/v2/end-users/auth/validate-token`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: validateEndUserAccessTokenBody,
    },
    options,
  );
};
/**
 * Gets an end user by ID.

This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Get end user
 */
export const getEndUser = (
  userId: string,
  options?: SecondParameter<typeof cdpApiClient<EndUser>>,
) => {
  return cdpApiClient<EndUser>({ url: `/v2/end-users/${userId}`, method: "GET" }, options);
};
/**
 * Looks up end users. Exactly one lookup type must be provided per request:

- **email**: searches across all email-based authentication methods
  (email, Google, Apple, GitHub). May return multiple end users if the
  same email address appears across different auth methods.

- **oauthProvider + oauthSubject**: looks up a user by their OAuth
  provider and subject (the `sub` claim from the provider's ID token).
  Both params must be provided together.

- **phoneNumber**: looks up a user by their SMS-verified phone number.
- **siweAddress**: looks up a user by the Ethereum address they authenticated
  with via Sign In With Ethereum (EIP-4361).


Returns all matching end users. If no end users match, an empty array is returned.

This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Look up end users by identity
 */
export const lookupEndUser = (
  params?: LookupEndUserParams,
  options?: SecondParameter<typeof cdpApiClient<LookupEndUser200>>,
) => {
  return cdpApiClient<LookupEndUser200>(
    { url: `/v2/end-users/lookup`, method: "GET", params },
    options,
  );
};
/**
 * Adds a new EVM EOA account to an existing end user. End users can have up to 10 EVM accounts.
This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Add EVM account to end user
 */
export const addEndUserEvmAccount = (
  userId: string,
  addEndUserEvmAccountBody?: AddEndUserEvmAccountBody,
  options?: SecondParameter<typeof cdpApiClient<AddEndUserEvmAccount201>>,
) => {
  return cdpApiClient<AddEndUserEvmAccount201>(
    {
      url: `/v2/end-users/${userId}/evm`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: addEndUserEvmAccountBody,
    },
    options,
  );
};
/**
 * Creates an EVM smart account for an existing end user. The backend will create a new EVM EOA account to serve as the owner of the smart account.
This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Add EVM smart account to end user
 */
export const addEndUserEvmSmartAccount = (
  userId: string,
  addEndUserEvmSmartAccountBody?: AddEndUserEvmSmartAccountBody,
  options?: SecondParameter<typeof cdpApiClient<AddEndUserEvmSmartAccount201>>,
) => {
  return cdpApiClient<AddEndUserEvmSmartAccount201>(
    {
      url: `/v2/end-users/${userId}/evm-smart-account`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: addEndUserEvmSmartAccountBody,
    },
    options,
  );
};
/**
 * Adds a new Solana account to an existing end user. End users can have up to 10 Solana accounts.
This API is intended to be used by the developer's own backend, and is authenticated using the developer's CDP API key.
 * @summary Add Solana account to end user
 */
export const addEndUserSolanaAccount = (
  userId: string,
  addEndUserSolanaAccountBody?: AddEndUserSolanaAccountBody,
  options?: SecondParameter<typeof cdpApiClient<AddEndUserSolanaAccount201>>,
) => {
  return cdpApiClient<AddEndUserSolanaAccount201>(
    {
      url: `/v2/end-users/${userId}/solana`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: addEndUserSolanaAccountBody,
    },
    options,
  );
};
/**
 * Imports an existing private key for an end user into the developer's CDP Project. The private key must be encrypted using the CDP SDK's encryption scheme before being sent to this endpoint. This API should be called from the [CDP SDK](https://github.com/coinbase/cdp-sdk) to ensure that the associated private key is properly encrypted.

This endpoint allows developers to import existing keys for their end users, supporting both EVM and Solana key types. The end user must have at least one authentication method configured.
 * @summary Import end user private key
 */
export const importEndUser = (
  importEndUserBody: ImportEndUserBody,
  options?: SecondParameter<typeof cdpApiClient<EndUser>>,
) => {
  return cdpApiClient<EndUser>(
    {
      url: `/v2/end-users/import`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: importEndUserBody,
    },
    options,
  );
};
export type CreateEndUserResult = NonNullable<Awaited<ReturnType<typeof createEndUser>>>;
export type ListEndUsersResult = NonNullable<Awaited<ReturnType<typeof listEndUsers>>>;
export type ValidateEndUserAccessTokenResult = NonNullable<
  Awaited<ReturnType<typeof validateEndUserAccessToken>>
>;
export type GetEndUserResult = NonNullable<Awaited<ReturnType<typeof getEndUser>>>;
export type LookupEndUserResult = NonNullable<Awaited<ReturnType<typeof lookupEndUser>>>;
export type AddEndUserEvmAccountResult = NonNullable<
  Awaited<ReturnType<typeof addEndUserEvmAccount>>
>;
export type AddEndUserEvmSmartAccountResult = NonNullable<
  Awaited<ReturnType<typeof addEndUserEvmSmartAccount>>
>;
export type AddEndUserSolanaAccountResult = NonNullable<
  Awaited<ReturnType<typeof addEndUserSolanaAccount>>
>;
export type ImportEndUserResult = NonNullable<Awaited<ReturnType<typeof importEndUser>>>;
