/* tslint:disable */
/* eslint-disable */
/**
 * CWMS Data API
 * CWMS REST API for Data Retrieval
 *
 * The version of the OpenAPI document: 2.4.0-2026.3.16
 * 
 *
 * 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 {
    ApiKey,
    ApiKeyFromJSON,
    ApiKeyToJSON,
    CdaError,
    CdaErrorFromJSON,
    CdaErrorToJSON,
} from '../models';

export interface DeleteAuthKeysWithKeyNameRequest {
    keyName: string;
}

export interface GetAuthKeysWithKeyNameRequest {
    keyName: string;
}

export interface PostAuthKeysRequest {
    apiKey?: ApiKey;
}

/**
 * 
 */
export class AuthorizationApi extends runtime.BaseAPI {

    /**
     * Delete API key for a user
     * Delete auth keys with keyName
     */
    async deleteAuthKeysWithKeyNameRaw(requestParameters: DeleteAuthKeysWithKeyNameRequest, initOverrides?: RequestInit): Promise<runtime.ApiResponse<ApiKey>> {
        if (requestParameters.keyName === null || requestParameters.keyName === undefined) {
            throw new runtime.RequiredError('keyName','Required parameter requestParameters.keyName was null or undefined when calling deleteAuthKeysWithKeyName.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        const response = await this.request({
            path: `/auth/keys/{key-name}`.replace(`{${"key-name"}}`, encodeURIComponent(String(requestParameters.keyName))),
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     * Delete API key for a user
     * Delete auth keys with keyName
     */
    async deleteAuthKeysWithKeyName(requestParameters: DeleteAuthKeysWithKeyNameRequest, initOverrides?: RequestInit): Promise<ApiKey> {
        const response = await this.deleteAuthKeysWithKeyNameRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * View all keys for the current user
     * Get auth keys
     */
    async getAuthKeysRaw(initOverrides?: RequestInit): Promise<runtime.ApiResponse<Array<ApiKey>>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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

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

    /**
     * View all keys for the current user
     * Get auth keys
     */
    async getAuthKeys(initOverrides?: RequestInit): Promise<Array<ApiKey>> {
        const response = await this.getAuthKeysRaw(initOverrides);
        return await response.value();
    }

    /**
     * View specific key
     * Get auth keys with keyName
     */
    async getAuthKeysWithKeyNameRaw(requestParameters: GetAuthKeysWithKeyNameRequest, initOverrides?: RequestInit): Promise<runtime.ApiResponse<ApiKey>> {
        if (requestParameters.keyName === null || requestParameters.keyName === undefined) {
            throw new runtime.RequiredError('keyName','Required parameter requestParameters.keyName was null or undefined when calling getAuthKeysWithKeyName.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        const response = await this.request({
            path: `/auth/keys/{key-name}`.replace(`{${"key-name"}}`, encodeURIComponent(String(requestParameters.keyName))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     * View specific key
     * Get auth keys with keyName
     */
    async getAuthKeysWithKeyName(requestParameters: GetAuthKeysWithKeyNameRequest, initOverrides?: RequestInit): Promise<ApiKey> {
        const response = await this.getAuthKeysWithKeyNameRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Create a new API Key for user. The randomly generated key is returned to the caller. A provided key will be ignored.
     * Post auth keys
     */
    async postAuthKeysRaw(requestParameters: PostAuthKeysRequest, initOverrides?: RequestInit): Promise<runtime.ApiResponse<ApiKey>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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

        const response = await this.request({
            path: `/auth/keys`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: ApiKeyToJSON(requestParameters.apiKey),
        }, initOverrides);

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

    /**
     * Create a new API Key for user. The randomly generated key is returned to the caller. A provided key will be ignored.
     * Post auth keys
     */
    async postAuthKeys(requestParameters: PostAuthKeysRequest = {}, initOverrides?: RequestInit): Promise<ApiKey> {
        const response = await this.postAuthKeysRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
