/* 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 {
  ApiAddDeviceRequest,
  ApiError,
  ApiRegisterNumberRequest,
  ApiUnregisterNumberRequest,
  ApiVerifyNumberSettings,
} from "../models/index.js";
import {
  ApiAddDeviceRequestFromJSON,
  ApiAddDeviceRequestToJSON,
  ApiErrorFromJSON,
  ApiErrorToJSON,
  ApiRegisterNumberRequestFromJSON,
  ApiRegisterNumberRequestToJSON,
  ApiUnregisterNumberRequestFromJSON,
  ApiUnregisterNumberRequestToJSON,
  ApiVerifyNumberSettingsFromJSON,
  ApiVerifyNumberSettingsToJSON,
} from "../models/index.js";

export interface V1DevicesNumberPostRequest {
  number: string;
  data: ApiAddDeviceRequest;
}

export interface V1QrcodelinkGetRequest {
  deviceName: string;
  qrcodeVersion?: number;
}

export interface V1RegisterNumberPostRequest {
  number: string;
  data?: ApiRegisterNumberRequest;
}

export interface V1RegisterNumberVerifyTokenPostRequest {
  number: string;
  token: string;
  data?: ApiVerifyNumberSettings;
}

export interface V1UnregisterNumberPostRequest {
  number: string;
  data?: ApiUnregisterNumberRequest;
}

/**
 *
 */
export class DevicesApi extends runtime.BaseAPI {
  /**
   * Links another device to this device. Only works, if this is the master device.
   * Links another device to this device.
   */
  async v1DevicesNumberPostRaw(
    requestParameters: V1DevicesNumberPostRequest,
    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 v1DevicesNumberPost().',
      );
    }

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

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Links another device to this device. Only works, if this is the master device.
   * Links another device to this device.
   */
  async v1DevicesNumberPost(
    requestParameters: V1DevicesNumberPostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.v1DevicesNumberPostRaw(requestParameters, initOverrides);
  }

  /**
   * Link device and generate QR code
   * Link device and generate QR code.
   */
  async v1QrcodelinkGetRaw(
    requestParameters: V1QrcodelinkGetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Blob>> {
    if (requestParameters["deviceName"] == null) {
      throw new runtime.RequiredError(
        "deviceName",
        'Required parameter "deviceName" was null or undefined when calling v1QrcodelinkGet().',
      );
    }

    const queryParameters: any = {};

    if (requestParameters["deviceName"] != null) {
      queryParameters["device_name"] = requestParameters["deviceName"];
    }

    if (requestParameters["qrcodeVersion"] != null) {
      queryParameters["qrcode_version"] = requestParameters["qrcodeVersion"];
    }

    const headerParameters: runtime.HTTPHeaders = {};

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

    return new runtime.BlobApiResponse(response) as any;
  }

  /**
   * Link device and generate QR code
   * Link device and generate QR code.
   */
  async v1QrcodelinkGet(
    requestParameters: V1QrcodelinkGetRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<Blob> {
    const response = await this.v1QrcodelinkGetRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Register a phone number with the signal network.
   * Register a phone number.
   */
  async v1RegisterNumberPostRaw(
    requestParameters: V1RegisterNumberPostRequest,
    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 v1RegisterNumberPost().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Register a phone number with the signal network.
   * Register a phone number.
   */
  async v1RegisterNumberPost(
    requestParameters: V1RegisterNumberPostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.v1RegisterNumberPostRaw(requestParameters, initOverrides);
  }

  /**
   * Verify a registered phone number with the signal network.
   * Verify a registered phone number.
   */
  async v1RegisterNumberVerifyTokenPostRaw(
    requestParameters: V1RegisterNumberVerifyTokenPostRequest,
    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 v1RegisterNumberVerifyTokenPost().',
      );
    }

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

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    const response = await this.request(
      {
        path: `/v1/register/{number}/verify/{token}`
          .replace(
            `{${"number"}}`,
            encodeURIComponent(String(requestParameters["number"])),
          )
          .replace(
            `{${"token"}}`,
            encodeURIComponent(String(requestParameters["token"])),
          ),
        method: "POST",
        headers: headerParameters,
        query: queryParameters,
        body: ApiVerifyNumberSettingsToJSON(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;
    }
  }

  /**
   * Verify a registered phone number with the signal network.
   * Verify a registered phone number.
   */
  async v1RegisterNumberVerifyTokenPost(
    requestParameters: V1RegisterNumberVerifyTokenPostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<string> {
    const response = await this.v1RegisterNumberVerifyTokenPostRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Disables push support for this device. **WARNING:** If *delete_account* is set to *true*, the account will be deleted from the Signal Server. This cannot be undone without loss.
   * Unregister a phone number.
   */
  async v1UnregisterNumberPostRaw(
    requestParameters: V1UnregisterNumberPostRequest,
    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 v1UnregisterNumberPost().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Disables push support for this device. **WARNING:** If *delete_account* is set to *true*, the account will be deleted from the Signal Server. This cannot be undone without loss.
   * Unregister a phone number.
   */
  async v1UnregisterNumberPost(
    requestParameters: V1UnregisterNumberPostRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.v1UnregisterNumberPostRaw(requestParameters, initOverrides);
  }
}
