/* 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 {
  HandlersMeResponse,
  HandlersUpdateMeRequest,
  ModelsUser,
} from "../models/index";
import {
  HandlersMeResponseFromJSON,
  HandlersMeResponseToJSON,
  HandlersUpdateMeRequestFromJSON,
  HandlersUpdateMeRequestToJSON,
  ModelsUserFromJSON,
  ModelsUserToJSON,
} from "../models/index";

export interface UpdateMeRequest {
  handlersUpdateMeRequest: HandlersUpdateMeRequest;
}

/**
 *
 */
export class MeApi extends runtime.BaseAPI {
  /**
   * Get current user profile
   */
  async getMeRaw(
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<HandlersMeResponse>> {
    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

    let urlPath = `/me`;

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

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

  /**
   * Get current user profile
   */
  async getMe(
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<HandlersMeResponse> {
    const response = await this.getMeRaw(initOverrides);
    return await response.value();
  }

  /**
   * Update current user profile
   */
  async updateMeRaw(
    requestParameters: UpdateMeRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<ModelsUser>> {
    if (requestParameters["handlersUpdateMeRequest"] == null) {
      throw new runtime.RequiredError(
        "handlersUpdateMeRequest",
        'Required parameter "handlersUpdateMeRequest" was null or undefined when calling updateMe().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

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

    let urlPath = `/me`;

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

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

  /**
   * Update current user profile
   */
  async updateMe(
    requestParameters: UpdateMeRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<ModelsUser> {
    const response = await this.updateMeRaw(requestParameters, initOverrides);
    return await response.value();
  }
}
