/* 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 {
  ApiError,
  ApiRateLimitChallengeRequest,
  ApiSetUsernameRequest,
  ApiUpdateAccountSettingsRequest,
  ClientSetUsernameResponse,
} from "../models/index.js";
import {
  ApiErrorFromJSON,
  ApiErrorToJSON,
  ApiRateLimitChallengeRequestFromJSON,
  ApiRateLimitChallengeRequestToJSON,
  ApiSetUsernameRequestFromJSON,
  ApiSetUsernameRequestToJSON,
  ApiUpdateAccountSettingsRequestFromJSON,
  ApiUpdateAccountSettingsRequestToJSON,
  ClientSetUsernameResponseFromJSON,
  ClientSetUsernameResponseToJSON,
} from "../models/index.js";

export interface V1AccountsNumberRateLimitChallengePostRequest {
  number: string;
  data: ApiRateLimitChallengeRequest;
}

export interface V1AccountsNumberSettingsPutRequest {
  number: string;
  data: ApiUpdateAccountSettingsRequest;
}

export interface V1AccountsNumberUsernameDeleteRequest {
  number: string;
}

export interface V1AccountsNumberUsernamePostRequest {
  number: string;
  data: ApiSetUsernameRequest;
}

/**
 *
 */
export class AccountsApi extends runtime.BaseAPI {
  /**
   * Lists all of the accounts linked or registered
   * List all accounts
   */
  async v1AccountsGetRaw(
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Array<string>>> {
    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    const response = await this.request(
      {
        path: `/v1/accounts`,
        method: "GET",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.JSONApiResponse<any>(response);
  }

  /**
   * Lists all of the accounts linked or registered
   * List all accounts
   */
  async v1AccountsGet(
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<Array<string>> {
    const response = await this.v1AccountsGetRaw(initOverrides);
    return await response.value();
  }

  /**
   * When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The \"challenge_token\" is the token from the failed send attempt. The \"captcha\" is the captcha result, starting with signalcaptcha://
   * Lift rate limit restrictions by solving a captcha.
   */
  async v1AccountsNumberRateLimitChallengePostRaw(
    requestParameters: V1AccountsNumberRateLimitChallengePostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["number"] == null) {
      throw new runtime.RequiredError(
        "number",
        'Required parameter "number" was null or undefined when calling v1AccountsNumberRateLimitChallengePost().',
      );
    }

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

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    const response = await this.request(
      {
        path: `/v1/accounts/{number}/rate-limit-challenge`.replace(
          `{${"number"}}`,
          encodeURIComponent(String(requestParameters["number"])),
        ),
        method: "POST",
        headers: headerParameters,
        query: queryParameters,
        body: ApiRateLimitChallengeRequestToJSON(requestParameters["data"]),
      },
      initOverrides,
    );

    return new runtime.VoidApiResponse(response);
  }

  /**
   * When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The \"challenge_token\" is the token from the failed send attempt. The \"captcha\" is the captcha result, starting with signalcaptcha://
   * Lift rate limit restrictions by solving a captcha.
   */
  async v1AccountsNumberRateLimitChallengePost(
    requestParameters: V1AccountsNumberRateLimitChallengePostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.v1AccountsNumberRateLimitChallengePostRaw(
      requestParameters,
      initOverrides,
    );
  }

  /**
   * Update the account attributes on the signal server.
   * Update the account settings.
   */
  async v1AccountsNumberSettingsPutRaw(
    requestParameters: V1AccountsNumberSettingsPutRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["number"] == null) {
      throw new runtime.RequiredError(
        "number",
        'Required parameter "number" was null or undefined when calling v1AccountsNumberSettingsPut().',
      );
    }

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

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Update the account attributes on the signal server.
   * Update the account settings.
   */
  async v1AccountsNumberSettingsPut(
    requestParameters: V1AccountsNumberSettingsPutRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.v1AccountsNumberSettingsPutRaw(requestParameters, initOverrides);
  }

  /**
   * Delete the username associated with this account.
   * Remove a username.
   */
  async v1AccountsNumberUsernameDeleteRaw(
    requestParameters: V1AccountsNumberUsernameDeleteRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["number"] == null) {
      throw new runtime.RequiredError(
        "number",
        'Required parameter "number" was null or undefined when calling v1AccountsNumberUsernameDelete().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Delete the username associated with this account.
   * Remove a username.
   */
  async v1AccountsNumberUsernameDelete(
    requestParameters: V1AccountsNumberUsernameDeleteRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.v1AccountsNumberUsernameDeleteRaw(
      requestParameters,
      initOverrides,
    );
  }

  /**
   * Allows to set the username that should be used for this account. This can either be just the nickname (e.g. test) or the complete username with discriminator (e.g. test.123). Returns the new username with discriminator and the username link.
   * Set a username.
   */
  async v1AccountsNumberUsernamePostRaw(
    requestParameters: V1AccountsNumberUsernamePostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<ClientSetUsernameResponse>> {
    if (requestParameters["number"] == null) {
      throw new runtime.RequiredError(
        "number",
        'Required parameter "number" was null or undefined when calling v1AccountsNumberUsernamePost().',
      );
    }

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

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

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

  /**
   * Allows to set the username that should be used for this account. This can either be just the nickname (e.g. test) or the complete username with discriminator (e.g. test.123). Returns the new username with discriminator and the username link.
   * Set a username.
   */
  async v1AccountsNumberUsernamePost(
    requestParameters: V1AccountsNumberUsernamePostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<ClientSetUsernameResponse | null | undefined> {
    const response = await this.v1AccountsNumberUsernamePostRaw(
      requestParameters,
      initOverrides,
    );
    switch (response.raw.status) {
      case 201:
        return await response.value();
      case 204:
        return null;
      default:
        return await response.value();
    }
  }
}
