/* tslint:disable */
/* eslint-disable */
/**
 * Montelo
 * Documentation for the Montelo API.
 *
 * The version of the OpenAPI document: 1.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 {
  DeleteSuccessDto,
  TraceWithLogsDto,
  TracesWithCountDto,
} from '../models/index';
import {
    DeleteSuccessDtoFromJSON,
    DeleteSuccessDtoToJSON,
    TraceWithLogsDtoFromJSON,
    TraceWithLogsDtoToJSON,
    TracesWithCountDtoFromJSON,
    TracesWithCountDtoToJSON,
} from '../models/index';

export interface TraceControllerDeleteTraceRequest {
    traceId: string;
}

export interface TraceControllerGetTraceRequest {
    traceId: string;
}

export interface TraceControllerGetTracesForEnvRequest {
    envId: string;
    take?: string;
    skip?: string;
    sortColumn?: string;
    sortDirection?: string;
    searchQuery?: string;
    startDate?: string;
    lastTimestamp?: string;
}

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

    /**
     */
    async traceControllerDeleteTraceRaw(requestParameters: TraceControllerDeleteTraceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<DeleteSuccessDto>> {
        if (requestParameters.traceId === null || requestParameters.traceId === undefined) {
            throw new runtime.RequiredError('traceId','Required parameter requestParameters.traceId was null or undefined when calling traceControllerDeleteTrace.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const response = await this.request({
            path: `/trace/{traceId}`.replace(`{${"traceId"}}`, encodeURIComponent(String(requestParameters.traceId))),
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async traceControllerDeleteTrace(requestParameters: TraceControllerDeleteTraceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<DeleteSuccessDto> {
        const response = await this.traceControllerDeleteTraceRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async traceControllerGetTraceRaw(requestParameters: TraceControllerGetTraceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<TraceWithLogsDto>> {
        if (requestParameters.traceId === null || requestParameters.traceId === undefined) {
            throw new runtime.RequiredError('traceId','Required parameter requestParameters.traceId was null or undefined when calling traceControllerGetTrace.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const response = await this.request({
            path: `/trace/{traceId}`.replace(`{${"traceId"}}`, encodeURIComponent(String(requestParameters.traceId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async traceControllerGetTrace(requestParameters: TraceControllerGetTraceRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TraceWithLogsDto> {
        const response = await this.traceControllerGetTraceRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

        const queryParameters: any = {};

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

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

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

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

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

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

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

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = await token("bearer", []);

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const response = await this.request({
            path: `/env/{envId}/trace`.replace(`{${"envId"}}`, encodeURIComponent(String(requestParameters.envId))),
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     */
    async traceControllerGetTracesForEnv(requestParameters: TraceControllerGetTracesForEnvRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TracesWithCountDto> {
        const response = await this.traceControllerGetTracesForEnvRaw(requestParameters, initOverrides);
        return await response.value();
    }

}
