/* tslint:disable */
/* eslint-disable */
/**
 * zrok
 * zrok client access
 *
 * The version of the OpenAPI document: 0.3.0
 * 
 *
 * 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 {
  Environment,
  EnvironmentAndResources,
  Frontend,
  Metrics,
  ModelConfiguration,
  Overview,
  Share,
} from '../models/index';
import {
    EnvironmentFromJSON,
    EnvironmentToJSON,
    EnvironmentAndResourcesFromJSON,
    EnvironmentAndResourcesToJSON,
    FrontendFromJSON,
    FrontendToJSON,
    MetricsFromJSON,
    MetricsToJSON,
    ModelConfigurationFromJSON,
    ModelConfigurationToJSON,
    OverviewFromJSON,
    OverviewToJSON,
    ShareFromJSON,
    ShareToJSON,
} from '../models/index';

export interface GetAccountMetricsRequest {
    duration?: string;
}

export interface GetEnvironmentDetailRequest {
    envZId: string;
}

export interface GetEnvironmentMetricsRequest {
    envId: string;
    duration?: string;
}

export interface GetFrontendDetailRequest {
    feId: number;
}

export interface GetShareDetailRequest {
    shrToken: string;
}

export interface GetShareMetricsRequest {
    shrToken: string;
    duration?: string;
}

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

    /**
     */
    async _configurationRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<ModelConfiguration>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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

    /**
     */
    async _configuration(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ModelConfiguration> {
        const response = await this._configurationRaw(initOverrides);
        return await response.value();
    }

    /**
     */
    async getAccountDetailRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<Environment>>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

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

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

    /**
     */
    async getAccountDetail(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<Environment>> {
        const response = await this.getAccountDetailRaw(initOverrides);
        return await response.value();
    }

    /**
     */
    async getAccountMetricsRaw(requestParameters: GetAccountMetricsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Metrics>> {
        const queryParameters: any = {};

        if (requestParameters.duration !== undefined) {
            queryParameters['duration'] = requestParameters.duration;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

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

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

    /**
     */
    async getAccountMetrics(requestParameters: GetAccountMetricsRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Metrics> {
        const response = await this.getAccountMetricsRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async getEnvironmentDetailRaw(requestParameters: GetEnvironmentDetailRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<EnvironmentAndResources>> {
        if (requestParameters.envZId === null || requestParameters.envZId === undefined) {
            throw new runtime.RequiredError('envZId','Required parameter requestParameters.envZId was null or undefined when calling getEnvironmentDetail.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

        const response = await this.request({
            path: `/detail/environment/{envZId}`.replace(`{${"envZId"}}`, encodeURIComponent(String(requestParameters.envZId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async getEnvironmentDetail(requestParameters: GetEnvironmentDetailRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<EnvironmentAndResources> {
        const response = await this.getEnvironmentDetailRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async getEnvironmentMetricsRaw(requestParameters: GetEnvironmentMetricsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Metrics>> {
        if (requestParameters.envId === null || requestParameters.envId === undefined) {
            throw new runtime.RequiredError('envId','Required parameter requestParameters.envId was null or undefined when calling getEnvironmentMetrics.');
        }

        const queryParameters: any = {};

        if (requestParameters.duration !== undefined) {
            queryParameters['duration'] = requestParameters.duration;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

        const response = await this.request({
            path: `/metrics/environment/{envId}`.replace(`{${"envId"}}`, encodeURIComponent(String(requestParameters.envId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async getEnvironmentMetrics(requestParameters: GetEnvironmentMetricsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Metrics> {
        const response = await this.getEnvironmentMetricsRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async getFrontendDetailRaw(requestParameters: GetFrontendDetailRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Frontend>> {
        if (requestParameters.feId === null || requestParameters.feId === undefined) {
            throw new runtime.RequiredError('feId','Required parameter requestParameters.feId was null or undefined when calling getFrontendDetail.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

        const response = await this.request({
            path: `/detail/frontend/{feId}`.replace(`{${"feId"}}`, encodeURIComponent(String(requestParameters.feId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async getFrontendDetail(requestParameters: GetFrontendDetailRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Frontend> {
        const response = await this.getFrontendDetailRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async getShareDetailRaw(requestParameters: GetShareDetailRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Share>> {
        if (requestParameters.shrToken === null || requestParameters.shrToken === undefined) {
            throw new runtime.RequiredError('shrToken','Required parameter requestParameters.shrToken was null or undefined when calling getShareDetail.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

        const response = await this.request({
            path: `/detail/share/{shrToken}`.replace(`{${"shrToken"}}`, encodeURIComponent(String(requestParameters.shrToken))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async getShareDetail(requestParameters: GetShareDetailRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Share> {
        const response = await this.getShareDetailRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async getShareMetricsRaw(requestParameters: GetShareMetricsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Metrics>> {
        if (requestParameters.shrToken === null || requestParameters.shrToken === undefined) {
            throw new runtime.RequiredError('shrToken','Required parameter requestParameters.shrToken was null or undefined when calling getShareMetrics.');
        }

        const queryParameters: any = {};

        if (requestParameters.duration !== undefined) {
            queryParameters['duration'] = requestParameters.duration;
        }

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

        const response = await this.request({
            path: `/metrics/share/{shrToken}`.replace(`{${"shrToken"}}`, encodeURIComponent(String(requestParameters.shrToken))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async getShareMetrics(requestParameters: GetShareMetricsRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Metrics> {
        const response = await this.getShareMetricsRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async overviewRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Overview>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["x-token"] = this.configuration.apiKey("x-token"); // key authentication
        }

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

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

    /**
     */
    async overview(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Overview> {
        const response = await this.overviewRaw(initOverrides);
        return await response.value();
    }

    /**
     */
    async versionRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<string>> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

        if (this.isJsonMime(response.headers.get('content-type'))) {
            return new runtime.JSONApiResponse<string>(response);
        } else {
            return new runtime.TextApiResponse(response) as any;
        }
    }

    /**
     */
    async version(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<string> {
        const response = await this.versionRaw(initOverrides);
        return await response.value();
    }

}
