// This file was auto-generated by Fern from our API Definition.

import type { BaseClientOptions, BaseRequestOptions } from "../../../../BaseClient.js";
import { type NormalizedClientOptionsWithAuth, normalizeClientOptionsWithAuth } from "../../../../BaseClient.js";
import { mergeHeaders } from "../../../../core/headers.js";
import * as core from "../../../../core/index.js";
import * as environments from "../../../../environments.js";
import { handleNonStatusCodeError } from "../../../../errors/handleNonStatusCodeError.js";
import * as errors from "../../../../errors/index.js";
import type * as Vapi from "../../../index.js";

export declare namespace ObservabilityScorecardClient {
    export type Options = BaseClientOptions;

    export interface RequestOptions extends BaseRequestOptions {}
}

export class ObservabilityScorecardClient {
    protected readonly _options: NormalizedClientOptionsWithAuth<ObservabilityScorecardClient.Options>;

    constructor(options: ObservabilityScorecardClient.Options) {
        this._options = normalizeClientOptionsWithAuth(options);
    }

    /**
     * @param {Vapi.ScorecardControllerGetRequest} request
     * @param {ObservabilityScorecardClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.observabilityScorecard.scorecardControllerGet({
     *         id: "id"
     *     })
     */
    public scorecardControllerGet(
        request: Vapi.ScorecardControllerGetRequest,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): core.HttpResponsePromise<Vapi.Scorecard> {
        return core.HttpResponsePromise.fromPromise(this.__scorecardControllerGet(request, requestOptions));
    }

    private async __scorecardControllerGet(
        request: Vapi.ScorecardControllerGetRequest,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): Promise<core.WithRawResponse<Vapi.Scorecard>> {
        const { id } = request;
        const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
        const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
            _authRequest.headers,
            this._options?.headers,
            requestOptions?.headers,
        );
        const _response = await (this._options.fetcher ?? core.fetcher)({
            url: core.url.join(
                (await core.Supplier.get(this._options.baseUrl)) ??
                    (await core.Supplier.get(this._options.environment)) ??
                    environments.VapiEnvironment.Default,
                `observability/scorecard/${core.url.encodePathParam(id)}`,
            ),
            method: "GET",
            headers: _headers,
            queryParameters: requestOptions?.queryParams,
            timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
            maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
            abortSignal: requestOptions?.abortSignal,
            fetchFn: this._options?.fetch,
            logging: this._options.logging,
        });
        if (_response.ok) {
            return { data: _response.body as Vapi.Scorecard, rawResponse: _response.rawResponse };
        }

        if (_response.error.reason === "status-code") {
            throw new errors.VapiError({
                statusCode: _response.error.statusCode,
                body: _response.error.body,
                rawResponse: _response.rawResponse,
            });
        }

        return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/observability/scorecard/{id}");
    }

    /**
     * @param {Vapi.ScorecardControllerRemoveRequest} request
     * @param {ObservabilityScorecardClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.observabilityScorecard.scorecardControllerRemove({
     *         id: "id"
     *     })
     */
    public scorecardControllerRemove(
        request: Vapi.ScorecardControllerRemoveRequest,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): core.HttpResponsePromise<Vapi.Scorecard> {
        return core.HttpResponsePromise.fromPromise(this.__scorecardControllerRemove(request, requestOptions));
    }

    private async __scorecardControllerRemove(
        request: Vapi.ScorecardControllerRemoveRequest,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): Promise<core.WithRawResponse<Vapi.Scorecard>> {
        const { id } = request;
        const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
        const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
            _authRequest.headers,
            this._options?.headers,
            requestOptions?.headers,
        );
        const _response = await (this._options.fetcher ?? core.fetcher)({
            url: core.url.join(
                (await core.Supplier.get(this._options.baseUrl)) ??
                    (await core.Supplier.get(this._options.environment)) ??
                    environments.VapiEnvironment.Default,
                `observability/scorecard/${core.url.encodePathParam(id)}`,
            ),
            method: "DELETE",
            headers: _headers,
            queryParameters: requestOptions?.queryParams,
            timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
            maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
            abortSignal: requestOptions?.abortSignal,
            fetchFn: this._options?.fetch,
            logging: this._options.logging,
        });
        if (_response.ok) {
            return { data: _response.body as Vapi.Scorecard, rawResponse: _response.rawResponse };
        }

        if (_response.error.reason === "status-code") {
            throw new errors.VapiError({
                statusCode: _response.error.statusCode,
                body: _response.error.body,
                rawResponse: _response.rawResponse,
            });
        }

        return handleNonStatusCodeError(
            _response.error,
            _response.rawResponse,
            "DELETE",
            "/observability/scorecard/{id}",
        );
    }

    /**
     * @param {Vapi.UpdateScorecardDto} request
     * @param {ObservabilityScorecardClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.observabilityScorecard.scorecardControllerUpdate({
     *         id: "id"
     *     })
     */
    public scorecardControllerUpdate(
        request: Vapi.UpdateScorecardDto,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): core.HttpResponsePromise<Vapi.Scorecard> {
        return core.HttpResponsePromise.fromPromise(this.__scorecardControllerUpdate(request, requestOptions));
    }

    private async __scorecardControllerUpdate(
        request: Vapi.UpdateScorecardDto,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): Promise<core.WithRawResponse<Vapi.Scorecard>> {
        const { id, ..._body } = request;
        const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
        const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
            _authRequest.headers,
            this._options?.headers,
            requestOptions?.headers,
        );
        const _response = await (this._options.fetcher ?? core.fetcher)({
            url: core.url.join(
                (await core.Supplier.get(this._options.baseUrl)) ??
                    (await core.Supplier.get(this._options.environment)) ??
                    environments.VapiEnvironment.Default,
                `observability/scorecard/${core.url.encodePathParam(id)}`,
            ),
            method: "PATCH",
            headers: _headers,
            contentType: "application/json",
            queryParameters: requestOptions?.queryParams,
            requestType: "json",
            body: _body,
            timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
            maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
            abortSignal: requestOptions?.abortSignal,
            fetchFn: this._options?.fetch,
            logging: this._options.logging,
        });
        if (_response.ok) {
            return { data: _response.body as Vapi.Scorecard, rawResponse: _response.rawResponse };
        }

        if (_response.error.reason === "status-code") {
            throw new errors.VapiError({
                statusCode: _response.error.statusCode,
                body: _response.error.body,
                rawResponse: _response.rawResponse,
            });
        }

        return handleNonStatusCodeError(
            _response.error,
            _response.rawResponse,
            "PATCH",
            "/observability/scorecard/{id}",
        );
    }

    /**
     * @param {Vapi.ScorecardControllerGetPaginatedRequest} request
     * @param {ObservabilityScorecardClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.observabilityScorecard.scorecardControllerGetPaginated()
     */
    public scorecardControllerGetPaginated(
        request: Vapi.ScorecardControllerGetPaginatedRequest = {},
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): core.HttpResponsePromise<Vapi.ScorecardPaginatedResponse> {
        return core.HttpResponsePromise.fromPromise(this.__scorecardControllerGetPaginated(request, requestOptions));
    }

    private async __scorecardControllerGetPaginated(
        request: Vapi.ScorecardControllerGetPaginatedRequest = {},
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): Promise<core.WithRawResponse<Vapi.ScorecardPaginatedResponse>> {
        const {
            id,
            page,
            sortOrder,
            limit,
            createdAtGt,
            createdAtLt,
            createdAtGe,
            createdAtLe,
            updatedAtGt,
            updatedAtLt,
            updatedAtGe,
            updatedAtLe,
        } = request;
        const _queryParams: Record<string, unknown> = {
            id,
            page,
            sortOrder: sortOrder != null ? sortOrder : undefined,
            limit,
            createdAtGt: createdAtGt != null ? createdAtGt : undefined,
            createdAtLt: createdAtLt != null ? createdAtLt : undefined,
            createdAtGe: createdAtGe != null ? createdAtGe : undefined,
            createdAtLe: createdAtLe != null ? createdAtLe : undefined,
            updatedAtGt: updatedAtGt != null ? updatedAtGt : undefined,
            updatedAtLt: updatedAtLt != null ? updatedAtLt : undefined,
            updatedAtGe: updatedAtGe != null ? updatedAtGe : undefined,
            updatedAtLe: updatedAtLe != null ? updatedAtLe : undefined,
        };
        const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
        const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
            _authRequest.headers,
            this._options?.headers,
            requestOptions?.headers,
        );
        const _response = await (this._options.fetcher ?? core.fetcher)({
            url: core.url.join(
                (await core.Supplier.get(this._options.baseUrl)) ??
                    (await core.Supplier.get(this._options.environment)) ??
                    environments.VapiEnvironment.Default,
                "observability/scorecard",
            ),
            method: "GET",
            headers: _headers,
            queryParameters: { ..._queryParams, ...requestOptions?.queryParams },
            timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
            maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
            abortSignal: requestOptions?.abortSignal,
            fetchFn: this._options?.fetch,
            logging: this._options.logging,
        });
        if (_response.ok) {
            return { data: _response.body as Vapi.ScorecardPaginatedResponse, rawResponse: _response.rawResponse };
        }

        if (_response.error.reason === "status-code") {
            throw new errors.VapiError({
                statusCode: _response.error.statusCode,
                body: _response.error.body,
                rawResponse: _response.rawResponse,
            });
        }

        return handleNonStatusCodeError(_response.error, _response.rawResponse, "GET", "/observability/scorecard");
    }

    /**
     * @param {Vapi.CreateScorecardDto} request
     * @param {ObservabilityScorecardClient.RequestOptions} requestOptions - Request-specific configuration.
     *
     * @example
     *     await client.observabilityScorecard.scorecardControllerCreate({
     *         metrics: [{
     *                 structuredOutputId: "structuredOutputId",
     *                 conditions: [{
     *                         "key": "value"
     *                     }]
     *             }]
     *     })
     */
    public scorecardControllerCreate(
        request: Vapi.CreateScorecardDto,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): core.HttpResponsePromise<Vapi.Scorecard> {
        return core.HttpResponsePromise.fromPromise(this.__scorecardControllerCreate(request, requestOptions));
    }

    private async __scorecardControllerCreate(
        request: Vapi.CreateScorecardDto,
        requestOptions?: ObservabilityScorecardClient.RequestOptions,
    ): Promise<core.WithRawResponse<Vapi.Scorecard>> {
        const _authRequest: core.AuthRequest = await this._options.authProvider.getAuthRequest();
        const _headers: core.Fetcher.Args["headers"] = mergeHeaders(
            _authRequest.headers,
            this._options?.headers,
            requestOptions?.headers,
        );
        const _response = await (this._options.fetcher ?? core.fetcher)({
            url: core.url.join(
                (await core.Supplier.get(this._options.baseUrl)) ??
                    (await core.Supplier.get(this._options.environment)) ??
                    environments.VapiEnvironment.Default,
                "observability/scorecard",
            ),
            method: "POST",
            headers: _headers,
            contentType: "application/json",
            queryParameters: requestOptions?.queryParams,
            requestType: "json",
            body: request,
            timeoutMs: (requestOptions?.timeoutInSeconds ?? this._options?.timeoutInSeconds ?? 60) * 1000,
            maxRetries: requestOptions?.maxRetries ?? this._options?.maxRetries,
            abortSignal: requestOptions?.abortSignal,
            fetchFn: this._options?.fetch,
            logging: this._options.logging,
        });
        if (_response.ok) {
            return { data: _response.body as Vapi.Scorecard, rawResponse: _response.rawResponse };
        }

        if (_response.error.reason === "status-code") {
            throw new errors.VapiError({
                statusCode: _response.error.statusCode,
                body: _response.error.body,
                rawResponse: _response.rawResponse,
            });
        }

        return handleNonStatusCodeError(_response.error, _response.rawResponse, "POST", "/observability/scorecard");
    }
}
