/* tslint:disable */
/* eslint-disable */
/**
 * AutoGlue API
 * API for managing K3s clusters across cloud providers
 *
 * The version of the OpenAPI document: dev
 *
 *
 * 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";
import type {
  DtoCreateTaintRequest,
  DtoTaintResponse,
  DtoUpdateTaintRequest,
} from "../models/index";
import {
  DtoCreateTaintRequestFromJSON,
  DtoCreateTaintRequestToJSON,
  DtoTaintResponseFromJSON,
  DtoTaintResponseToJSON,
  DtoUpdateTaintRequestFromJSON,
  DtoUpdateTaintRequestToJSON,
} from "../models/index";

export interface CreateTaintRequest {
  dtoCreateTaintRequest: DtoCreateTaintRequest;
  xOrgID?: string;
}

export interface DeleteTaintRequest {
  id: string;
  xOrgID?: string;
}

export interface GetTaintRequest {
  id: string;
  xOrgID?: string;
}

export interface ListTaintsRequest {
  xOrgID?: string;
  key?: string;
  value?: string;
  q?: string;
}

export interface UpdateTaintRequest {
  id: string;
  dtoUpdateTaintRequest: DtoUpdateTaintRequest;
  xOrgID?: string;
}

/**
 *
 */
export class TaintsApi extends runtime.BaseAPI {
  /**
   * Creates a taint.
   * Create node taint (org scoped)
   */
  async createTaintRaw(
    requestParameters: CreateTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoTaintResponse>> {
    if (requestParameters["dtoCreateTaintRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoCreateTaintRequest",
        'Required parameter "dtoCreateTaintRequest" was null or undefined when calling createTaint().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/taints`;

    const response = await this.request(
      {
        path: urlPath,
        method: "POST",
        headers: headerParameters,
        query: queryParameters,
        body: DtoCreateTaintRequestToJSON(
          requestParameters["dtoCreateTaintRequest"],
        ),
      },
      initOverrides,
    );

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

  /**
   * Creates a taint.
   * Create node taint (org scoped)
   */
  async createTaint(
    requestParameters: CreateTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoTaintResponse> {
    const response = await this.createTaintRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Permanently deletes the taint.
   * Delete taint (org scoped)
   */
  async deleteTaintRaw(
    requestParameters: DeleteTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling deleteTaint().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/taints/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "DELETE",
        headers: headerParameters,
        query: queryParameters,
      },
      initOverrides,
    );

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Permanently deletes the taint.
   * Delete taint (org scoped)
   */
  async deleteTaint(
    requestParameters: DeleteTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.deleteTaintRaw(requestParameters, initOverrides);
  }

  /**
   * Get node taint by ID (org scoped)
   */
  async getTaintRaw(
    requestParameters: GetTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoTaintResponse>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling getTaint().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/taints/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

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

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

  /**
   * Get node taint by ID (org scoped)
   */
  async getTaint(
    requestParameters: GetTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoTaintResponse> {
    const response = await this.getTaintRaw(requestParameters, initOverrides);
    return await response.value();
  }

  /**
   * Returns node taints for the organization in X-Org-ID. Filters: `key`, `value`, and `q` (key contains). Add `include=node_pools` to include linked node pools.
   * List node pool taints (org scoped)
   */
  async listTaintsRaw(
    requestParameters: ListTaintsRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Array<DtoTaintResponse>>> {
    const queryParameters: any = {};

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

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

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

    const headerParameters: runtime.HTTPHeaders = {};

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/taints`;

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

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

  /**
   * Returns node taints for the organization in X-Org-ID. Filters: `key`, `value`, and `q` (key contains). Add `include=node_pools` to include linked node pools.
   * List node pool taints (org scoped)
   */
  async listTaints(
    requestParameters: ListTaintsRequest = {},
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<Array<DtoTaintResponse>> {
    const response = await this.listTaintsRaw(requestParameters, initOverrides);
    return await response.value();
  }

  /**
   * Partially update taint fields.
   * Update node taint (org scoped)
   */
  async updateTaintRaw(
    requestParameters: UpdateTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoTaintResponse>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling updateTaint().',
      );
    }

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

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    if (requestParameters["xOrgID"] != null) {
      headerParameters["X-Org-ID"] = String(requestParameters["xOrgID"]);
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-KEY"] =
        await this.configuration.apiKey("X-ORG-KEY"); // OrgKeyAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["X-ORG-SECRET"] =
        await this.configuration.apiKey("X-ORG-SECRET"); // OrgSecretAuth authentication
    }

    if (this.configuration && this.configuration.apiKey) {
      headerParameters["Authorization"] =
        await this.configuration.apiKey("Authorization"); // BearerAuth authentication
    }

    let urlPath = `/taints/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

    const response = await this.request(
      {
        path: urlPath,
        method: "PATCH",
        headers: headerParameters,
        query: queryParameters,
        body: DtoUpdateTaintRequestToJSON(
          requestParameters["dtoUpdateTaintRequest"],
        ),
      },
      initOverrides,
    );

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

  /**
   * Partially update taint fields.
   * Update node taint (org scoped)
   */
  async updateTaint(
    requestParameters: UpdateTaintRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoTaintResponse> {
    const response = await this.updateTaintRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }
}
