/* 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 {
  DtoCreateLabelRequest,
  DtoLabelResponse,
  DtoUpdateLabelRequest,
} from "../models/index";
import {
  DtoCreateLabelRequestFromJSON,
  DtoCreateLabelRequestToJSON,
  DtoLabelResponseFromJSON,
  DtoLabelResponseToJSON,
  DtoUpdateLabelRequestFromJSON,
  DtoUpdateLabelRequestToJSON,
} from "../models/index";

export interface CreateLabelRequest {
  dtoCreateLabelRequest: DtoCreateLabelRequest;
  xOrgID?: string;
}

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

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

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

export interface UpdateLabelRequest {
  id: string;
  dtoUpdateLabelRequest: DtoUpdateLabelRequest;
  xOrgID?: string;
}

/**
 *
 */
export class LabelsApi extends runtime.BaseAPI {
  /**
   * Creates a label.
   * Create label (org scoped)
   */
  async createLabelRaw(
    requestParameters: CreateLabelRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoLabelResponse>> {
    if (requestParameters["dtoCreateLabelRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoCreateLabelRequest",
        'Required parameter "dtoCreateLabelRequest" was null or undefined when calling createLabel().',
      );
    }

    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 = `/labels`;

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

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

  /**
   * Creates a label.
   * Create label (org scoped)
   */
  async createLabel(
    requestParameters: CreateLabelRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoLabelResponse> {
    const response = await this.createLabelRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Permanently deletes the label.
   * Delete label (org scoped)
   */
  async deleteLabelRaw(
    requestParameters: DeleteLabelRequest,
    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 deleteLabel().',
      );
    }

    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 = `/labels/{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 label.
   * Delete label (org scoped)
   */
  async deleteLabel(
    requestParameters: DeleteLabelRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.deleteLabelRaw(requestParameters, initOverrides);
  }

  /**
   * Returns one label.
   * Get label by ID (org scoped)
   */
  async getLabelRaw(
    requestParameters: GetLabelRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoLabelResponse>> {
    if (requestParameters["id"] == null) {
      throw new runtime.RequiredError(
        "id",
        'Required parameter "id" was null or undefined when calling getLabel().',
      );
    }

    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 = `/labels/{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) =>
      DtoLabelResponseFromJSON(jsonValue),
    );
  }

  /**
   * Returns one label.
   * Get label by ID (org scoped)
   */
  async getLabel(
    requestParameters: GetLabelRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoLabelResponse> {
    const response = await this.getLabelRaw(requestParameters, initOverrides);
    return await response.value();
  }

  /**
   * Returns node labels for the organization in X-Org-ID. Filters: `key`, `value`, and `q` (key contains). Add `include=node_pools` to include linked node groups.
   * List node labels (org scoped)
   */
  async listLabelsRaw(
    requestParameters: ListLabelsRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<Array<DtoLabelResponse>>> {
    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 = `/labels`;

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

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

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

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

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

    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 = `/labels/{id}`;
    urlPath = urlPath.replace(
      `{${"id"}}`,
      encodeURIComponent(String(requestParameters["id"])),
    );

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

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

  /**
   * Partially update label fields.
   * Update label (org scoped)
   */
  async updateLabel(
    requestParameters: UpdateLabelRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoLabelResponse> {
    const response = await this.updateLabelRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }
}
