/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import { agreementManagerAgreementsChangeAgreementType } from "../funcs/agreementManagerAgreementsChangeAgreementType.js";
import { agreementManagerAgreementsDeleteAgreement } from "../funcs/agreementManagerAgreementsDeleteAgreement.js";
import { agreementManagerAgreementsGetAgreement } from "../funcs/agreementManagerAgreementsGetAgreement.js";
import { agreementManagerAgreementsGetAgreementsList } from "../funcs/agreementManagerAgreementsGetAgreementsList.js";
import { agreementManagerAgreementsGetAgreementTypes } from "../funcs/agreementManagerAgreementsGetAgreementTypes.js";
import { agreementManagerAgreementsPatchAgreement } from "../funcs/agreementManagerAgreementsPatchAgreement.js";
import { agreementManagerAgreementsPatchAgreementByDocumentId } from "../funcs/agreementManagerAgreementsPatchAgreementByDocumentId.js";
import { ClientSDK, RequestOptions } from "../lib/sdks.js";
import * as components from "../models/components/index.js";
import * as operations from "../models/operations/index.js";
import { unwrapAsync } from "../types/fp.js";

export class Agreements extends ClientSDK {
  /**
   * Retrieve a list of agreements
   *
   * @remarks
   * This operation retrieves a list of all agreements available in the system. It provides a high-level overview of each agreement, including its unique identifier (`id`), title, type, status, and involved parties. The list also includes important metadata, such as the agreement's creation and modification timestamps, and information on the agreement's source system (e.g., eSign, CLM).
   *
   * Each agreement entry includes essential details that allow users to quickly assess the agreements and determine which ones are relevant for their needs. For example, the agreement's status can help users understand whether an agreement is still active, pending, or completed.
   *
   * The response also includes provisions that outline the key legal, financial, and lifecycle conditions, along with custom user-defined fields, providing a comprehensive understanding of each agreement.
   *
   * ### Use Cases:
   * - **Retrieving a list of agreements for integration into external systems**: Export or sync agreement data into other platforms (e.g., CRM, ERP systems) to align business processes across different tools.
   * - **Providing data for RAG (Retrieval-Augmented Generation) applications or Copilots**: The list of agreements can be a valuable data source for AI/LLM-based applications that answer user queries about agreements.
   *
   *   It allows Copilots to understand what agreements exist and offer insights based on their details.
   * - **Filtering agreements by type or status**: Determine which agreements are active, pending, or completed, and gather a summary of key provisions across multiple agreements.
   * - **Auditing or reporting**: Generate a report on agreements based on type, status, or date created, helping with compliance tracking and internal reviews.
   * - **Metadata tracking**: Track when agreements were created, modified, and by whom, ensuring proper governance and version control.
   *
   * ### Key Features:
   * - **Comprehensive Agreement Overview**: Provides high-level visibility into all agreements, with essential details for each one, including status, type, and involved parties.
   * - **Metadata and Provisions**: Returns important metadata and provisions (legal, financial, and custom) for each agreement, helping users understand their obligations and contract terms.
   * - **Source System Information**: Captures details about where the agreement originated (e.g., eSign, CLM), making it easier to integrate and track agreements across different business systems.
   * - **Data for AI Applications**: The operation is designed to support LLM-powered apps, making it ideal for use in RAG-based applications and Copilots that query agreements for decision-making or information purposes.
   */
  async getAgreementsList(
    request: operations.GetAgreementsListRequest,
    options?: RequestOptions,
  ): Promise<components.AgreementsResponse> {
    return unwrapAsync(agreementManagerAgreementsGetAgreementsList(
      this,
      request,
      options,
    ));
  }

  /**
   * Update an agreement by locating it via document ID
   *
   * @remarks
   * This operation updates a specific agreement by first locating it using its associated `document_id`.
   * This is useful when the client knows the document storage identifier but not the agreement ID.
   *
   * The operation accepts a `document_id` query parameter to uniquely identify the agreement, then applies the partial updates specified in the request body.
   * The system will search for an agreement containing the specified document ID, and if found, apply the requested modifications.
   * The operation returns a `204 No Content` response on success.
   *
   * This endpoint provides an alternative way to update agreements when the agreement ID is not readily available, making it convenient for systems that primarily work with document references rather than agreement identifiers.
   *
   * ### Use Cases:
   * - **Updating agreements referenced by document storage ID**: When integration points provide document IDs but not agreement IDs, this endpoint allows direct updates without a prior lookup.
   * - **Batch updating via external document references**: Systems that track agreements through external document management systems can update agreements using their document storage identifiers.
   * - **Cross-system synchronization**: Update agreements based on document references from external systems (e.g., content management systems, document repositories) without maintaining agreement ID mappings.
   * - **Document-centric workflows**: In document-first business processes, update agreements using the document reference that users are familiar with.
   *
   * ### Key Features:
   * - **Document ID Based Lookup**: Locate agreements by their associated document storage identifier rather than requiring the agreement ID upfront.
   * - **Automatic Resolution**: The system automatically finds the agreement associated with the provided document ID.
   * - **Partial Updates**: Modify only the fields you need; other agreement data remains unchanged.
   */
  async patchAgreementByDocumentId(
    request: operations.PatchAgreementByDocumentIdRequest,
    options?: RequestOptions,
  ): Promise<void> {
    return unwrapAsync(agreementManagerAgreementsPatchAgreementByDocumentId(
      this,
      request,
      options,
    ));
  }

  /**
   * List configured agreement types for the account.
   *
   * @remarks
   * Returns the list of agreement type names configured for the specified account as a simple array of strings.
   *
   * Use this endpoint to discover the available agreement types so that users can see the options to choose from. The returned type names can then be used with the change type endpoint (`PATCH /v1/accounts/{accountId}/agreements/{agreementId}/actions/change-type`) to change the type of an existing agreement.
   */
  async getAgreementTypes(
    request: operations.GetAgreementTypesRequest,
    options?: RequestOptions,
  ): Promise<Array<string>> {
    return unwrapAsync(agreementManagerAgreementsGetAgreementTypes(
      this,
      request,
      options,
    ));
  }

  /**
   * Retrieve detailed information about a specific agreement
   *
   * @remarks
   * This operation retrieves detailed information about a specific agreement, identified by its unique `id`. The response provides a comprehensive view of the agreement, including its title, type, status, summary, and the full list of involved parties.
   *
   * In addition to general details, the operation returns provisions that define the agreement's legal, financial, lifecycle, and custom conditions. It also provides key metadata, such as creation and modification timestamps, related agreements, and user-defined or custom attributes, which help represent the structure and context of the agreement.
   *
   * The operation is essential for retrieving the full context of an agreement, enabling users to understand the contract's scope, key provisions, and the legal or financial obligations that have been agreed upon.
   *
   * ### Use Cases:
   * - **Integrating agreement data into external systems**: Sync detailed agreement information, such as legal and financial provisions, into external systems like ERP, CRM, or contract management tools to streamline workflows.
   * - **Providing detailed data for RAG (Retrieval-Augmented Generation) applications or Copilots**: Retrieve detailed agreement data for use in LLM-based applications that answer specific user queries about their agreements, such as the status of a contract, its provisions, or involved parties.
   * - **Retrieving the complete details of a specific agreement**: Use the full details of the agreement, including legal and financial provisions, for auditing, compliance, or review purposes.
   * - **Accessing agreement provisions for verification**: Verify compliance with specific legal or financial terms of the agreement, ensuring that all parties are following the agreed-upon conditions.
   * - **Tracking agreement changes and history**: Fetch metadata and related agreements to understand the evolution of an agreement, including modifications, associated agreements, and additional context provided by custom fields.
   * - **Reviewing user-defined or custom attributes**: Examine custom fields or attributes to get more context about the agreement, particularly where the business has defined custom provisions or attributes.
   *
   * ### Key Features:
   * - **Detailed Agreement Overview**: Provides a comprehensive view of a specific agreement, including its title, type, status, summary, and more.
   * - **Provisions for Legal, Financial, and Lifecycle Conditions**: Includes the full set of provisions that define the terms and conditions of the agreement, making it ideal for compliance and auditing purposes.
   * - **Metadata and History**: Tracks the agreement’s history through metadata such as creation and modification dates and user-defined fields.
   * - **Data Source for AI Applications**: Enables LLM-based applications to access granular agreement data, providing AI/ML-based solutions (such as Copilots) with the necessary context to answer detailed queries about an agreement.
   * - **Involved Parties and Related Agreements**: Lists all parties involved and related agreements, allowing users to see all associated legal documents and relationships between agreements.
   */
  async getAgreement(
    request: operations.GetAgreementRequest,
    options?: RequestOptions,
  ): Promise<components.Agreement> {
    return unwrapAsync(agreementManagerAgreementsGetAgreement(
      this,
      request,
      options,
    ));
  }

  /**
   * Delete a specific agreement
   *
   * @remarks
   * This operation safely deletes an agreement. This action conforms to GDPR and CCPA compliance requirements.
   */
  async deleteAgreement(
    request: operations.DeleteAgreementRequest,
    options?: RequestOptions,
  ): Promise<void> {
    return unwrapAsync(agreementManagerAgreementsDeleteAgreement(
      this,
      request,
      options,
    ));
  }

  /**
   * Update specific fields of an agreement
   *
   * @remarks
   * This operation updates one or more fields of a specific agreement identified by its `agreementId`.
   * The operation supports partial updates, allowing clients to modify only the fields they need without affecting the rest of the agreement data.
   *
   * The request body should contain a JSON payload with the fields to be updated. Only the fields provided in the request body will be modified; all other fields remain unchanged. The operation returns a `204 No Content` response on success.
   *
   * This operation is essential for maintaining and evolving agreement data throughout the agreement's lifecycle, such as updating status, provisions, custom fields, or metadata based on business events or reviews.
   *
   * ### Use Cases:
   * - **Updating agreement status or review completion**: Mark agreements as reviewed, completed, or pending further action based on internal workflows.
   * - **Modifying provision details**: Update agreement terms, effective dates, expiration dates, or renewal conditions as circumstances change.
   * - **Managing custom attributes**: Add or modify user-defined fields and custom metadata to capture additional business context for the agreement.
   * - **Recording business events**: Update agreements to reflect changes such as amendments, renewals, or termination notices.
   * - **Synchronizing agreements across systems**: Update agreements in response to changes detected in external systems (e.g., ERP, CRM) to maintain data integrity.
   *
   * ### Key Features:
   * - **Partial Updates**: Modify only the fields you need; other agreement data remains intact.
   * - **Flexible Payload**: Accept JSON objects with any combination of updateable agreement fields, including provisions, metadata, and custom attributes.
   * - **Data Integrity**: Validates all input data to ensure compliance with agreement structure and data constraints.
   */
  async patchAgreement(
    request: operations.PatchAgreementRequest,
    options?: RequestOptions,
  ): Promise<void> {
    return unwrapAsync(agreementManagerAgreementsPatchAgreement(
      this,
      request,
      options,
    ));
  }

  /**
   * Change the type of an agreement
   *
   * @remarks
   * Changes the type of an existing agreement to a different configured type.
   * The target type must exist in the account's agreement-types collection.
   * Upon successful change, the server recomputes the category based on the new type.
   */
  async changeAgreementType(
    request: operations.ChangeAgreementTypeRequest,
    options?: RequestOptions,
  ): Promise<components.ChangeAgreementTypeResponse> {
    return unwrapAsync(agreementManagerAgreementsChangeAgreementType(
      this,
      request,
      options,
    ));
  }
}
