/**
 * 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 {
  CreatePolicyBody,
  ListPolicies200,
  ListPoliciesParams,
  Policy,
  UpdatePolicyBody,
} from "../coinbaseDeveloperPlatformAPIs.schemas.js";

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

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

/**
 * Lists the policies belonging to the developer's CDP Project. Use the `scope` parameter to filter the policies by scope.
The response is paginated, and by default, returns 20 policies per page.
 * @summary List policies
 */
export const listPolicies = (
  params?: ListPoliciesParams,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<ListPolicies200>(
    { url: `/v2/policy-engine/policies`, method: "GET", params },
    options,
  );
};
/**
 * Create a policy that can be used to govern the behavior of accounts.
 * @summary Create a policy
 */
export const createPolicy = (
  createPolicyBody: CreatePolicyBody,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<Policy>(
    {
      url: `/v2/policy-engine/policies`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: createPolicyBody,
    },
    options,
  );
};
/**
 * Get a policy by its ID.
 * @summary Get a policy by ID
 */
export const getPolicyById = (policyId: string, options?: SecondParameter<typeof cdpApiClient>) => {
  return cdpApiClient<Policy>(
    { url: `/v2/policy-engine/policies/${policyId}`, method: "GET" },
    options,
  );
};
/**
 * Delete a policy by its ID. This will have the effect of removing the policy from all accounts that are currently using it.
 * @summary Delete a policy
 */
export const deletePolicy = (policyId: string, options?: SecondParameter<typeof cdpApiClient>) => {
  return cdpApiClient<void>(
    { url: `/v2/policy-engine/policies/${policyId}`, method: "DELETE" },
    options,
  );
};
/**
 * Updates a policy by its ID. This will have the effect of applying the updated policy to all accounts that are currently using it.
 * @summary Update a policy
 */
export const updatePolicy = (
  policyId: string,
  updatePolicyBody: UpdatePolicyBody,
  options?: SecondParameter<typeof cdpApiClient>,
) => {
  return cdpApiClient<Policy>(
    {
      url: `/v2/policy-engine/policies/${policyId}`,
      method: "PUT",
      headers: { "Content-Type": "application/json" },
      data: updatePolicyBody,
    },
    options,
  );
};
export type ListPoliciesResult = NonNullable<Awaited<ReturnType<typeof listPolicies>>>;
export type CreatePolicyResult = NonNullable<Awaited<ReturnType<typeof createPolicy>>>;
export type GetPolicyByIdResult = NonNullable<Awaited<ReturnType<typeof getPolicyById>>>;
export type DeletePolicyResult = NonNullable<Awaited<ReturnType<typeof deletePolicy>>>;
export type UpdatePolicyResult = NonNullable<Awaited<ReturnType<typeof updatePolicy>>>;
