/* 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 {
  DtoAuthStartResponse,
  DtoJWKS,
  DtoLogoutRequest,
  DtoRefreshRequest,
  DtoTokenPair,
} from "../models/index";
import {
  DtoAuthStartResponseFromJSON,
  DtoAuthStartResponseToJSON,
  DtoJWKSFromJSON,
  DtoJWKSToJSON,
  DtoLogoutRequestFromJSON,
  DtoLogoutRequestToJSON,
  DtoRefreshRequestFromJSON,
  DtoRefreshRequestToJSON,
  DtoTokenPairFromJSON,
  DtoTokenPairToJSON,
} from "../models/index";

export interface AuthCallbackRequest {
  provider: string;
}

export interface AuthStartRequest {
  provider: string;
}

export interface LogoutRequest {
  dtoLogoutRequest: DtoLogoutRequest;
}

export interface RefreshRequest {
  dtoRefreshRequest: DtoRefreshRequest;
}

/**
 *
 */
export class AuthApi extends runtime.BaseAPI {
  /**
   * Handle social login callback
   */
  async authCallbackRaw(
    requestParameters: AuthCallbackRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoTokenPair>> {
    if (requestParameters["provider"] == null) {
      throw new runtime.RequiredError(
        "provider",
        'Required parameter "provider" was null or undefined when calling authCallback().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

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

  /**
   * Handle social login callback
   */
  async authCallback(
    requestParameters: AuthCallbackRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoTokenPair> {
    const response = await this.authCallbackRaw(
      requestParameters,
      initOverrides,
    );
    return await response.value();
  }

  /**
   * Returns provider authorization URL for the frontend to redirect
   * Begin social login
   */
  async authStartRaw(
    requestParameters: AuthStartRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoAuthStartResponse>> {
    if (requestParameters["provider"] == null) {
      throw new runtime.RequiredError(
        "provider",
        'Required parameter "provider" was null or undefined when calling authStart().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

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

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

  /**
   * Returns provider authorization URL for the frontend to redirect
   * Begin social login
   */
  async authStart(
    requestParameters: AuthStartRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoAuthStartResponse> {
    const response = await this.authStartRaw(requestParameters, initOverrides);
    return await response.value();
  }

  /**
   * Returns the JSON Web Key Set for token verification
   * Get JWKS
   */
  async getJWKSRaw(
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoJWKS>> {
    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

    let urlPath = `/.well-known/jwks.json`;

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

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

  /**
   * Returns the JSON Web Key Set for token verification
   * Get JWKS
   */
  async getJWKS(
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoJWKS> {
    const response = await this.getJWKSRaw(initOverrides);
    return await response.value();
  }

  /**
   * Revoke refresh token family (logout everywhere)
   */
  async logoutRaw(
    requestParameters: LogoutRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<void>> {
    if (requestParameters["dtoLogoutRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoLogoutRequest",
        'Required parameter "dtoLogoutRequest" was null or undefined when calling logout().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    let urlPath = `/auth/logout`;

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

    return new runtime.VoidApiResponse(response);
  }

  /**
   * Revoke refresh token family (logout everywhere)
   */
  async logout(
    requestParameters: LogoutRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<void> {
    await this.logoutRaw(requestParameters, initOverrides);
  }

  /**
   * Rotate refresh token
   */
  async refreshRaw(
    requestParameters: RefreshRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<runtime.ApiResponse<DtoTokenPair>> {
    if (requestParameters["dtoRefreshRequest"] == null) {
      throw new runtime.RequiredError(
        "dtoRefreshRequest",
        'Required parameter "dtoRefreshRequest" was null or undefined when calling refresh().',
      );
    }

    const queryParameters: any = {};

    const headerParameters: runtime.HTTPHeaders = {};

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

    let urlPath = `/auth/refresh`;

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

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

  /**
   * Rotate refresh token
   */
  async refresh(
    requestParameters: RefreshRequest,
    initOverrides?: RequestInit | runtime.InitOverrideFunction,
  ): Promise<DtoTokenPair> {
    const response = await this.refreshRaw(requestParameters, initOverrides);
    return await response.value();
  }
}
