/* tslint:disable */
/* eslint-disable */
/**
 * KubeBlocks Cloud API
 * KubeBlocks Cloud API is a RESTful API for managing KubeBlocks Cloud resources.  The API is organized around REST.  Our API has predictable resource-oriented URLs, accepts `JSON-encoded` request bodies, returns `JSON-encoded` responses, and uses standard HTTP response codes, authentication, and verbs.  We use standard HTTP authentication and provide API keys to identify who you are. Your API keys carry many privileges, so be sure to keep them secret! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth. 
 *
 * The version of the OpenAPI document: 1.0.0
 * Contact: support@apecloud.com
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import type { Configuration } from '../configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
// Some imports not used depending on template conditions
// @ts-ignore
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base';
// @ts-ignore
import type { APIErrorResponse } from '../models';
// @ts-ignore
import type { CreatePgExtensionResp } from '../models';
// @ts-ignore
import type { PgCreateExtensionOpt } from '../models';
// @ts-ignore
import type { PgExtension } from '../models';
/**
 * PostgresqlApi - axios parameter creator
 * @export
 */
export const PostgresqlApiAxiosParamCreator = function (configuration?: Configuration) {
    return {
        /**
         * create PostgreSQL extension
         * @summary create PostgreSQL extension
         * @param {string} orgName Organization name
         * @param {string} clusterName name of the cluster
         * @param {PgCreateExtensionOpt} pgCreateExtensionOpt 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        createPGExtension: async (orgName: string, clusterName: string, pgCreateExtensionOpt: PgCreateExtensionOpt, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'orgName' is not null or undefined
            assertParamExists('createPGExtension', 'orgName', orgName)
            // verify required parameter 'clusterName' is not null or undefined
            assertParamExists('createPGExtension', 'clusterName', clusterName)
            // verify required parameter 'pgCreateExtensionOpt' is not null or undefined
            assertParamExists('createPGExtension', 'pgCreateExtensionOpt', pgCreateExtensionOpt)
            const localVarPath = `/api/v1/data/postgresql/organizations/{orgName}/clusters/{clusterName}/extensions`
                .replace(`{${"orgName"}}`, encodeURIComponent(String(orgName)))
                .replace(`{${"clusterName"}}`, encodeURIComponent(String(clusterName)));
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions;
            }

            const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication BearerToken required
            // http bearer authentication required
            await setBearerAuthToObject(localVarHeaderParameter, configuration)

            // authentication DigestAuth required
            await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration)


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

            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};
            localVarRequestOptions.data = serializeDataIfNeeded(pgCreateExtensionOpt, localVarRequestOptions, configuration)

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
        /**
         * drop PostgreSQL extension
         * @summary drop PostgreSQL extension
         * @param {string} orgName Organization name
         * @param {string} clusterName name of the cluster
         * @param {string} extensionName The name of the PostgreSQL extension to uninstall.
         * @param {string} database The database where the extension is installed.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        dropPGExtension: async (orgName: string, clusterName: string, extensionName: string, database: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'orgName' is not null or undefined
            assertParamExists('dropPGExtension', 'orgName', orgName)
            // verify required parameter 'clusterName' is not null or undefined
            assertParamExists('dropPGExtension', 'clusterName', clusterName)
            // verify required parameter 'extensionName' is not null or undefined
            assertParamExists('dropPGExtension', 'extensionName', extensionName)
            // verify required parameter 'database' is not null or undefined
            assertParamExists('dropPGExtension', 'database', database)
            const localVarPath = `/api/v1/data/postgresql/organizations/{orgName}/clusters/{clusterName}/extensions/{extensionName}`
                .replace(`{${"orgName"}}`, encodeURIComponent(String(orgName)))
                .replace(`{${"clusterName"}}`, encodeURIComponent(String(clusterName)))
                .replace(`{${"extensionName"}}`, encodeURIComponent(String(extensionName)));
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions;
            }

            const localVarRequestOptions = { method: 'DELETE', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication BearerToken required
            // http bearer authentication required
            await setBearerAuthToObject(localVarHeaderParameter, configuration)

            // authentication DigestAuth required
            await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration)

            if (database !== undefined) {
                localVarQueryParameter['database'] = database;
            }


    
            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
        /**
         * List PostgreSQL extensions
         * @summary List PostgreSQL extensions
         * @param {string} orgName Organization name
         * @param {string} clusterName name of the cluster
         * @param {string} [status] extension status, if set to &#x60;installed&#x60;, only installed extensions will be returned. If not specified, all available extensions will be returned.
         * @param {string} [database] database name. This parameter is only used when status is installed; if not specified, all databases installed extensions will be returned.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listPGExtensions: async (orgName: string, clusterName: string, status?: string, database?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
            // verify required parameter 'orgName' is not null or undefined
            assertParamExists('listPGExtensions', 'orgName', orgName)
            // verify required parameter 'clusterName' is not null or undefined
            assertParamExists('listPGExtensions', 'clusterName', clusterName)
            const localVarPath = `/api/v1/data/postgresql/organizations/{orgName}/clusters/{clusterName}/extensions`
                .replace(`{${"orgName"}}`, encodeURIComponent(String(orgName)))
                .replace(`{${"clusterName"}}`, encodeURIComponent(String(clusterName)));
            // use dummy base URL string because the URL constructor only accepts absolute URLs.
            const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
            let baseOptions;
            if (configuration) {
                baseOptions = configuration.baseOptions;
            }

            const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
            const localVarHeaderParameter = {} as any;
            const localVarQueryParameter = {} as any;

            // authentication BearerToken required
            // http bearer authentication required
            await setBearerAuthToObject(localVarHeaderParameter, configuration)

            // authentication DigestAuth required
            await setApiKeyToObject(localVarHeaderParameter, "Authorization", configuration)

            if (status !== undefined) {
                localVarQueryParameter['status'] = status;
            }

            if (database !== undefined) {
                localVarQueryParameter['database'] = database;
            }


    
            setSearchParams(localVarUrlObj, localVarQueryParameter);
            let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
            localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

            return {
                url: toPathString(localVarUrlObj),
                options: localVarRequestOptions,
            };
        },
    }
};

/**
 * PostgresqlApi - functional programming interface
 * @export
 */
export const PostgresqlApiFp = function(configuration?: Configuration) {
    const localVarAxiosParamCreator = PostgresqlApiAxiosParamCreator(configuration)
    return {
        /**
         * create PostgreSQL extension
         * @summary create PostgreSQL extension
         * @param {string} orgName Organization name
         * @param {string} clusterName name of the cluster
         * @param {PgCreateExtensionOpt} pgCreateExtensionOpt 
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async createPGExtension(orgName: string, clusterName: string, pgCreateExtensionOpt: PgCreateExtensionOpt, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<CreatePgExtensionResp>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.createPGExtension(orgName, clusterName, pgCreateExtensionOpt, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['PostgresqlApi.createPGExtension']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * drop PostgreSQL extension
         * @summary drop PostgreSQL extension
         * @param {string} orgName Organization name
         * @param {string} clusterName name of the cluster
         * @param {string} extensionName The name of the PostgreSQL extension to uninstall.
         * @param {string} database The database where the extension is installed.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async dropPGExtension(orgName: string, clusterName: string, extensionName: string, database: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<void>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.dropPGExtension(orgName, clusterName, extensionName, database, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['PostgresqlApi.dropPGExtension']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
        /**
         * List PostgreSQL extensions
         * @summary List PostgreSQL extensions
         * @param {string} orgName Organization name
         * @param {string} clusterName name of the cluster
         * @param {string} [status] extension status, if set to &#x60;installed&#x60;, only installed extensions will be returned. If not specified, all available extensions will be returned.
         * @param {string} [database] database name. This parameter is only used when status is installed; if not specified, all databases installed extensions will be returned.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        async listPGExtensions(orgName: string, clusterName: string, status?: string, database?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<PgExtension>>> {
            const localVarAxiosArgs = await localVarAxiosParamCreator.listPGExtensions(orgName, clusterName, status, database, options);
            const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
            const localVarOperationServerBasePath = operationServerMap['PostgresqlApi.listPGExtensions']?.[localVarOperationServerIndex]?.url;
            return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
        },
    }
};

/**
 * PostgresqlApi - factory interface
 * @export
 */
export const PostgresqlApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
    const localVarFp = PostgresqlApiFp(configuration)
    return {
        /**
         * create PostgreSQL extension
         * @summary create PostgreSQL extension
         * @param {PostgresqlApiCreatePGExtensionRequest} requestParameters Request parameters.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        createPGExtension(requestParameters: PostgresqlApiCreatePGExtensionRequest, options?: RawAxiosRequestConfig): AxiosPromise<CreatePgExtensionResp> {
            return localVarFp.createPGExtension(requestParameters.orgName, requestParameters.clusterName, requestParameters.pgCreateExtensionOpt, options).then((request) => request(axios, basePath));
        },
        /**
         * drop PostgreSQL extension
         * @summary drop PostgreSQL extension
         * @param {PostgresqlApiDropPGExtensionRequest} requestParameters Request parameters.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        dropPGExtension(requestParameters: PostgresqlApiDropPGExtensionRequest, options?: RawAxiosRequestConfig): AxiosPromise<void> {
            return localVarFp.dropPGExtension(requestParameters.orgName, requestParameters.clusterName, requestParameters.extensionName, requestParameters.database, options).then((request) => request(axios, basePath));
        },
        /**
         * List PostgreSQL extensions
         * @summary List PostgreSQL extensions
         * @param {PostgresqlApiListPGExtensionsRequest} requestParameters Request parameters.
         * @param {*} [options] Override http request option.
         * @throws {RequiredError}
         */
        listPGExtensions(requestParameters: PostgresqlApiListPGExtensionsRequest, options?: RawAxiosRequestConfig): AxiosPromise<Array<PgExtension>> {
            return localVarFp.listPGExtensions(requestParameters.orgName, requestParameters.clusterName, requestParameters.status, requestParameters.database, options).then((request) => request(axios, basePath));
        },
    };
};

/**
 * PostgresqlApi - interface
 * @export
 * @interface PostgresqlApi
 */
export interface PostgresqlApiInterface {
    /**
     * create PostgreSQL extension
     * @summary create PostgreSQL extension
     * @param {PostgresqlApiCreatePGExtensionRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof PostgresqlApiInterface
     */
    createPGExtension(requestParameters: PostgresqlApiCreatePGExtensionRequest, options?: RawAxiosRequestConfig): AxiosPromise<CreatePgExtensionResp>;

    /**
     * drop PostgreSQL extension
     * @summary drop PostgreSQL extension
     * @param {PostgresqlApiDropPGExtensionRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof PostgresqlApiInterface
     */
    dropPGExtension(requestParameters: PostgresqlApiDropPGExtensionRequest, options?: RawAxiosRequestConfig): AxiosPromise<void>;

    /**
     * List PostgreSQL extensions
     * @summary List PostgreSQL extensions
     * @param {PostgresqlApiListPGExtensionsRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof PostgresqlApiInterface
     */
    listPGExtensions(requestParameters: PostgresqlApiListPGExtensionsRequest, options?: RawAxiosRequestConfig): AxiosPromise<Array<PgExtension>>;

}

/**
 * Request parameters for createPGExtension operation in PostgresqlApi.
 * @export
 * @interface PostgresqlApiCreatePGExtensionRequest
 */
export interface PostgresqlApiCreatePGExtensionRequest {
    /**
     * Organization name
     * @type {string}
     * @memberof PostgresqlApiCreatePGExtension
     */
    readonly orgName: string

    /**
     * name of the cluster
     * @type {string}
     * @memberof PostgresqlApiCreatePGExtension
     */
    readonly clusterName: string

    /**
     * 
     * @type {PgCreateExtensionOpt}
     * @memberof PostgresqlApiCreatePGExtension
     */
    readonly pgCreateExtensionOpt: PgCreateExtensionOpt
}

/**
 * Request parameters for dropPGExtension operation in PostgresqlApi.
 * @export
 * @interface PostgresqlApiDropPGExtensionRequest
 */
export interface PostgresqlApiDropPGExtensionRequest {
    /**
     * Organization name
     * @type {string}
     * @memberof PostgresqlApiDropPGExtension
     */
    readonly orgName: string

    /**
     * name of the cluster
     * @type {string}
     * @memberof PostgresqlApiDropPGExtension
     */
    readonly clusterName: string

    /**
     * The name of the PostgreSQL extension to uninstall.
     * @type {string}
     * @memberof PostgresqlApiDropPGExtension
     */
    readonly extensionName: string

    /**
     * The database where the extension is installed.
     * @type {string}
     * @memberof PostgresqlApiDropPGExtension
     */
    readonly database: string
}

/**
 * Request parameters for listPGExtensions operation in PostgresqlApi.
 * @export
 * @interface PostgresqlApiListPGExtensionsRequest
 */
export interface PostgresqlApiListPGExtensionsRequest {
    /**
     * Organization name
     * @type {string}
     * @memberof PostgresqlApiListPGExtensions
     */
    readonly orgName: string

    /**
     * name of the cluster
     * @type {string}
     * @memberof PostgresqlApiListPGExtensions
     */
    readonly clusterName: string

    /**
     * extension status, if set to &#x60;installed&#x60;, only installed extensions will be returned. If not specified, all available extensions will be returned.
     * @type {string}
     * @memberof PostgresqlApiListPGExtensions
     */
    readonly status?: string

    /**
     * database name. This parameter is only used when status is installed; if not specified, all databases installed extensions will be returned.
     * @type {string}
     * @memberof PostgresqlApiListPGExtensions
     */
    readonly database?: string
}

/**
 * PostgresqlApi - object-oriented interface
 * @export
 * @class PostgresqlApi
 * @extends {BaseAPI}
 */
export class PostgresqlApi extends BaseAPI implements PostgresqlApiInterface {
    /**
     * create PostgreSQL extension
     * @summary create PostgreSQL extension
     * @param {PostgresqlApiCreatePGExtensionRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof PostgresqlApi
     */
    public createPGExtension(requestParameters: PostgresqlApiCreatePGExtensionRequest, options?: RawAxiosRequestConfig) {
        return PostgresqlApiFp(this.configuration).createPGExtension(requestParameters.orgName, requestParameters.clusterName, requestParameters.pgCreateExtensionOpt, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * drop PostgreSQL extension
     * @summary drop PostgreSQL extension
     * @param {PostgresqlApiDropPGExtensionRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof PostgresqlApi
     */
    public dropPGExtension(requestParameters: PostgresqlApiDropPGExtensionRequest, options?: RawAxiosRequestConfig) {
        return PostgresqlApiFp(this.configuration).dropPGExtension(requestParameters.orgName, requestParameters.clusterName, requestParameters.extensionName, requestParameters.database, options).then((request) => request(this.axios, this.basePath));
    }

    /**
     * List PostgreSQL extensions
     * @summary List PostgreSQL extensions
     * @param {PostgresqlApiListPGExtensionsRequest} requestParameters Request parameters.
     * @param {*} [options] Override http request option.
     * @throws {RequiredError}
     * @memberof PostgresqlApi
     */
    public listPGExtensions(requestParameters: PostgresqlApiListPGExtensionsRequest, options?: RawAxiosRequestConfig) {
        return PostgresqlApiFp(this.configuration).listPGExtensions(requestParameters.orgName, requestParameters.clusterName, requestParameters.status, requestParameters.database, options).then((request) => request(this.axios, this.basePath));
    }
}

