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

import { portalCreateSession } from "../funcs/portalCreateSession.js";
import { portalExchangeSession } from "../funcs/portalExchangeSession.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 Portal extends ClientSDK {
  /**
   * Create portal session
   *
   * @remarks
   * Create a short-lived session token for an end user to access the Customer Portal.
   *
   * The returned session ID is valid for 15 minutes and can be exchanged exactly once
   * for a 24-hour browser session via `portal.exchangeSession`. Redirect the end user
   * to the returned URL to start the portal experience.
   *
   * **Required Permissions**
   *
   * Your root key must be associated with a workspace that has an enabled portal configuration.
   */
  async createSession(
    request: components.V2PortalCreateSessionRequestBody,
    options?: RequestOptions,
  ): Promise<operations.PortalCreateSessionResponse> {
    return unwrapAsync(portalCreateSession(
      this,
      request,
      options,
    ));
  }

  /**
   * Exchange session token
   *
   * @remarks
   * Exchange a short-lived session token for a long-lived browser session.
   *
   * This endpoint is unauthenticated. The session token itself serves as proof of authorization.
   * Each token can only be exchanged once; subsequent attempts return 401.
   *
   * The returned browser session token is valid for 24 hours and should be stored as an
   * httpOnly cookie or used in the Authorization header for subsequent API calls.
   */
  async exchangeSession(
    request: components.V2PortalExchangeSessionRequestBody,
    options?: RequestOptions,
  ): Promise<operations.PortalExchangeSessionResponse> {
    return unwrapAsync(portalExchangeSession(
      this,
      request,
      options,
    ));
  }
}
