/* tslint:disable */
/* eslint-disable */
/**
 * Signal Cli REST API
 * This is the Signal Cli REST API documentation.
 *
 * The version of the OpenAPI document: 1.0
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

import * as runtime from "../runtime.js";
import type {
  ApiTrustIdentityRequest,
  ClientIdentityEntry,
} from "../models/index.js";
import {
  ApiTrustIdentityRequestFromJSON,
  ApiTrustIdentityRequestToJSON,
  ClientIdentityEntryFromJSON,
  ClientIdentityEntryToJSON,
} from "../models/index.js";

export interface V1IdentitiesNumberGetRequest {
  number: string;
}

export interface V1IdentitiesNumberTrustNumberToTrustPutRequest {
  number: string;
  numberToTrust: string;
  data: ApiTrustIdentityRequest;
}

/**
 *
 */
export class IdentitiesApi extends runtime.BaseAPI {
  /**
   * List all identities for the given number.
   * List Identities
   */
  async v1IdentitiesNumberGetRaw(
    requestParameters: V1IdentitiesNumberGetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Array<ClientIdentityEntry>>> {
    if (requestParameters["number"] == null) {
      throw new runtime.RequiredError(
        "number",
        'Required parameter "number" was null or undefined when calling v1IdentitiesNumberGet().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    const response = await this.request(
      {
        path: `/v1/identities/{number}`.replace(
          `{${"number"}}`,
          encodeURIComponent(String(requestParameters["number"])),
        ),
        method: "GET",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse(response, (jsonValue) =>
      jsonValue.map(ClientIdentityEntryFromJSON),
    );
  }

  /**
   * List all identities for the given number.
   * List Identities
   */
  async v1IdentitiesNumberGet(
    requestParameters: V1IdentitiesNumberGetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<Array<ClientIdentityEntry>> {
    const response = await this.v1IdentitiesNumberGetRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Trust an identity. When \'trust_all_known_keys\' is set to\' true\', all known keys of this user are trusted. **This is only recommended for testing.**
   * Trust Identity
   */
  async v1IdentitiesNumberTrustNumberToTrustPutRaw(
    requestParameters: V1IdentitiesNumberTrustNumberToTrustPutRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<string>> {
    if (requestParameters["number"] == null) {
      throw new runtime.RequiredError(
        "number",
        'Required parameter "number" was null or undefined when calling v1IdentitiesNumberTrustNumberToTrustPut().',
      );
    }

    if (requestParameters["numberToTrust"] == null) {
      throw new runtime.RequiredError(
        "numberToTrust",
        'Required parameter "numberToTrust" was null or undefined when calling v1IdentitiesNumberTrustNumberToTrustPut().',
      );
    }

    if (requestParameters["data"] == null) {
      throw new runtime.RequiredError(
        "data",
        'Required parameter "data" was null or undefined when calling v1IdentitiesNumberTrustNumberToTrustPut().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    headerParameters["Content-Type"] = "application/json";

    const response = await this.request(
      {
        path: `/v1/identities/{number}/trust/{numberToTrust}`
          .replace(
            `{${"number"}}`,
            encodeURIComponent(String(requestParameters["number"])),
          )
          .replace(
            `{${"numberToTrust"}}`,
            encodeURIComponent(String(requestParameters["numberToTrust"])),
          ),
        method: "PUT",
        headers: headerParameters,
        query: queryParameters,
        body: ApiTrustIdentityRequestToJSON(requestParameters["data"]),
      },
      initOverrides,
    );

    if (this.isJsonMime(response.headers.get("content-type"))) {
      return new runtime.JSONApiResponse<string>(response);
    } else {
      return new runtime.TextApiResponse(response) as any;
    }
  }

  /**
   * Trust an identity. When \'trust_all_known_keys\' is set to\' true\', all known keys of this user are trusted. **This is only recommended for testing.**
   * Trust Identity
   */
  async v1IdentitiesNumberTrustNumberToTrustPut(
    requestParameters: V1IdentitiesNumberTrustNumberToTrustPutRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<string> {
    const response = await this.v1IdentitiesNumberTrustNumberToTrustPutRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }
}
