/* tslint:disable */
/* eslint-disable */
/**
 * authentik
 * Making authentication simple.
 *
 * The version of the OpenAPI document: 2026.5.0-rc1
 * Contact: hello@goauthentik.io
 *
 * 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 {
    BlueprintFile,
    BlueprintImportResult,
    BlueprintInstance,
    BlueprintInstanceRequest,
    PaginatedBlueprintInstanceList,
    PatchedBlueprintInstanceRequest,
    UsedBy,
} from "../models/index";
import {
    BlueprintFileFromJSON,
    BlueprintImportResultFromJSON,
    BlueprintInstanceFromJSON,
    BlueprintInstanceRequestToJSON,
    PaginatedBlueprintInstanceListFromJSON,
    PatchedBlueprintInstanceRequestToJSON,
    UsedByFromJSON,
} from "../models/index";
import * as runtime from "../runtime";

export interface ManagedBlueprintsApplyCreateRequest {
    instanceUuid: string;
}

export interface ManagedBlueprintsCreateRequest {
    blueprintInstanceRequest: BlueprintInstanceRequest;
}

export interface ManagedBlueprintsDestroyRequest {
    instanceUuid: string;
}

export interface ManagedBlueprintsImportCreateRequest {
    file?: Blob;
    path?: string;
}

export interface ManagedBlueprintsListRequest {
    name?: string;
    ordering?: string;
    page?: number;
    pageSize?: number;
    path?: string;
    search?: string;
}

export interface ManagedBlueprintsPartialUpdateRequest {
    instanceUuid: string;
    patchedBlueprintInstanceRequest?: PatchedBlueprintInstanceRequest;
}

export interface ManagedBlueprintsRetrieveRequest {
    instanceUuid: string;
}

export interface ManagedBlueprintsUpdateRequest {
    instanceUuid: string;
    blueprintInstanceRequest: BlueprintInstanceRequest;
}

export interface ManagedBlueprintsUsedByListRequest {
    instanceUuid: string;
}

/**
 *
 */
export class ManagedApi extends runtime.BaseAPI {
    /**
     * Creates request options for managedBlueprintsApplyCreate without sending the request
     */
    async managedBlueprintsApplyCreateRequestOpts(
        requestParameters: ManagedBlueprintsApplyCreateRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["instanceUuid"] == null) {
            throw new runtime.RequiredError(
                "instanceUuid",
                'Required parameter "instanceUuid" was null or undefined when calling managedBlueprintsApplyCreate().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/{instance_uuid}/apply/`;
        urlPath = urlPath.replace(
            `{${"instance_uuid"}}`,
            encodeURIComponent(String(requestParameters["instanceUuid"])),
        );

        return {
            path: urlPath,
            method: "POST",
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Apply a blueprint
     */
    async managedBlueprintsApplyCreateRaw(
        requestParameters: ManagedBlueprintsApplyCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<BlueprintInstance>> {
        const requestOptions =
            await this.managedBlueprintsApplyCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Apply a blueprint
     */
    async managedBlueprintsApplyCreate(
        requestParameters: ManagedBlueprintsApplyCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<BlueprintInstance> {
        const response = await this.managedBlueprintsApplyCreateRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsAvailableList without sending the request
     */
    async managedBlueprintsAvailableListRequestOpts(): Promise<runtime.RequestOpts> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/available/`;

        return {
            path: urlPath,
            method: "GET",
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Get blueprints
     */
    async managedBlueprintsAvailableListRaw(
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Array<BlueprintFile>>> {
        const requestOptions = await this.managedBlueprintsAvailableListRequestOpts();
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Get blueprints
     */
    async managedBlueprintsAvailableList(
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Array<BlueprintFile>> {
        const response = await this.managedBlueprintsAvailableListRaw(initOverrides);
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsCreate without sending the request
     */
    async managedBlueprintsCreateRequestOpts(
        requestParameters: ManagedBlueprintsCreateRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["blueprintInstanceRequest"] == null) {
            throw new runtime.RequiredError(
                "blueprintInstanceRequest",
                'Required parameter "blueprintInstanceRequest" was null or undefined when calling managedBlueprintsCreate().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/`;

        return {
            path: urlPath,
            method: "POST",
            headers: headerParameters,
            query: queryParameters,
            body: BlueprintInstanceRequestToJSON(requestParameters["blueprintInstanceRequest"]),
        };
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsCreateRaw(
        requestParameters: ManagedBlueprintsCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<BlueprintInstance>> {
        const requestOptions = await this.managedBlueprintsCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Blueprint instances
     */
    async managedBlueprintsCreate(
        requestParameters: ManagedBlueprintsCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<BlueprintInstance> {
        const response = await this.managedBlueprintsCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsDestroy without sending the request
     */
    async managedBlueprintsDestroyRequestOpts(
        requestParameters: ManagedBlueprintsDestroyRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["instanceUuid"] == null) {
            throw new runtime.RequiredError(
                "instanceUuid",
                'Required parameter "instanceUuid" was null or undefined when calling managedBlueprintsDestroy().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/{instance_uuid}/`;
        urlPath = urlPath.replace(
            `{${"instance_uuid"}}`,
            encodeURIComponent(String(requestParameters["instanceUuid"])),
        );

        return {
            path: urlPath,
            method: "DELETE",
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsDestroyRaw(
        requestParameters: ManagedBlueprintsDestroyRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<void>> {
        const requestOptions = await this.managedBlueprintsDestroyRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsDestroy(
        requestParameters: ManagedBlueprintsDestroyRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<void> {
        await this.managedBlueprintsDestroyRaw(requestParameters, initOverrides);
    }

    /**
     * Creates request options for managedBlueprintsImportCreate without sending the request
     */
    async managedBlueprintsImportCreateRequestOpts(
        requestParameters: ManagedBlueprintsImportCreateRequest,
    ): Promise<runtime.RequestOpts> {
        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        const consumes: runtime.Consume[] = [{ contentType: "multipart/form-data" }];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any };
        let useForm = false;
        // use FormData to transmit files using content-type "multipart/form-data"
        useForm = canConsumeForm;
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new URLSearchParams();
        }

        if (requestParameters["file"] != null) {
            formParams.append("file", requestParameters["file"] as any);
        }

        if (requestParameters["path"] != null) {
            formParams.append("path", requestParameters["path"] as any);
        }

        let urlPath = `/managed/blueprints/import/`;

        return {
            path: urlPath,
            method: "POST",
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        };
    }

    /**
     * Import blueprint from .yaml file and apply it once, without creating an instance
     */
    async managedBlueprintsImportCreateRaw(
        requestParameters: ManagedBlueprintsImportCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<BlueprintImportResult>> {
        const requestOptions =
            await this.managedBlueprintsImportCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Import blueprint from .yaml file and apply it once, without creating an instance
     */
    async managedBlueprintsImportCreate(
        requestParameters: ManagedBlueprintsImportCreateRequest = {},
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<BlueprintImportResult> {
        const response = await this.managedBlueprintsImportCreateRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsList without sending the request
     */
    async managedBlueprintsListRequestOpts(
        requestParameters: ManagedBlueprintsListRequest,
    ): Promise<runtime.RequestOpts> {
        const queryParameters: any = {};

        if (requestParameters["name"] != null) {
            queryParameters["name"] = requestParameters["name"];
        }

        if (requestParameters["ordering"] != null) {
            queryParameters["ordering"] = requestParameters["ordering"];
        }

        if (requestParameters["page"] != null) {
            queryParameters["page"] = requestParameters["page"];
        }

        if (requestParameters["pageSize"] != null) {
            queryParameters["page_size"] = requestParameters["pageSize"];
        }

        if (requestParameters["path"] != null) {
            queryParameters["path"] = requestParameters["path"];
        }

        if (requestParameters["search"] != null) {
            queryParameters["search"] = requestParameters["search"];
        }

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/`;

        return {
            path: urlPath,
            method: "GET",
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsListRaw(
        requestParameters: ManagedBlueprintsListRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<PaginatedBlueprintInstanceList>> {
        const requestOptions = await this.managedBlueprintsListRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Blueprint instances
     */
    async managedBlueprintsList(
        requestParameters: ManagedBlueprintsListRequest = {},
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<PaginatedBlueprintInstanceList> {
        const response = await this.managedBlueprintsListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsPartialUpdate without sending the request
     */
    async managedBlueprintsPartialUpdateRequestOpts(
        requestParameters: ManagedBlueprintsPartialUpdateRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["instanceUuid"] == null) {
            throw new runtime.RequiredError(
                "instanceUuid",
                'Required parameter "instanceUuid" was null or undefined when calling managedBlueprintsPartialUpdate().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/{instance_uuid}/`;
        urlPath = urlPath.replace(
            `{${"instance_uuid"}}`,
            encodeURIComponent(String(requestParameters["instanceUuid"])),
        );

        return {
            path: urlPath,
            method: "PATCH",
            headers: headerParameters,
            query: queryParameters,
            body: PatchedBlueprintInstanceRequestToJSON(
                requestParameters["patchedBlueprintInstanceRequest"],
            ),
        };
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsPartialUpdateRaw(
        requestParameters: ManagedBlueprintsPartialUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<BlueprintInstance>> {
        const requestOptions =
            await this.managedBlueprintsPartialUpdateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Blueprint instances
     */
    async managedBlueprintsPartialUpdate(
        requestParameters: ManagedBlueprintsPartialUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<BlueprintInstance> {
        const response = await this.managedBlueprintsPartialUpdateRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsRetrieve without sending the request
     */
    async managedBlueprintsRetrieveRequestOpts(
        requestParameters: ManagedBlueprintsRetrieveRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["instanceUuid"] == null) {
            throw new runtime.RequiredError(
                "instanceUuid",
                'Required parameter "instanceUuid" was null or undefined when calling managedBlueprintsRetrieve().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/{instance_uuid}/`;
        urlPath = urlPath.replace(
            `{${"instance_uuid"}}`,
            encodeURIComponent(String(requestParameters["instanceUuid"])),
        );

        return {
            path: urlPath,
            method: "GET",
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsRetrieveRaw(
        requestParameters: ManagedBlueprintsRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<BlueprintInstance>> {
        const requestOptions = await this.managedBlueprintsRetrieveRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Blueprint instances
     */
    async managedBlueprintsRetrieve(
        requestParameters: ManagedBlueprintsRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<BlueprintInstance> {
        const response = await this.managedBlueprintsRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsUpdate without sending the request
     */
    async managedBlueprintsUpdateRequestOpts(
        requestParameters: ManagedBlueprintsUpdateRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["instanceUuid"] == null) {
            throw new runtime.RequiredError(
                "instanceUuid",
                'Required parameter "instanceUuid" was null or undefined when calling managedBlueprintsUpdate().',
            );
        }

        if (requestParameters["blueprintInstanceRequest"] == null) {
            throw new runtime.RequiredError(
                "blueprintInstanceRequest",
                'Required parameter "blueprintInstanceRequest" was null or undefined when calling managedBlueprintsUpdate().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/{instance_uuid}/`;
        urlPath = urlPath.replace(
            `{${"instance_uuid"}}`,
            encodeURIComponent(String(requestParameters["instanceUuid"])),
        );

        return {
            path: urlPath,
            method: "PUT",
            headers: headerParameters,
            query: queryParameters,
            body: BlueprintInstanceRequestToJSON(requestParameters["blueprintInstanceRequest"]),
        };
    }

    /**
     * Blueprint instances
     */
    async managedBlueprintsUpdateRaw(
        requestParameters: ManagedBlueprintsUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<BlueprintInstance>> {
        const requestOptions = await this.managedBlueprintsUpdateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Blueprint instances
     */
    async managedBlueprintsUpdate(
        requestParameters: ManagedBlueprintsUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<BlueprintInstance> {
        const response = await this.managedBlueprintsUpdateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Creates request options for managedBlueprintsUsedByList without sending the request
     */
    async managedBlueprintsUsedByListRequestOpts(
        requestParameters: ManagedBlueprintsUsedByListRequest,
    ): Promise<runtime.RequestOpts> {
        if (requestParameters["instanceUuid"] == null) {
            throw new runtime.RequiredError(
                "instanceUuid",
                'Required parameter "instanceUuid" was null or undefined when calling managedBlueprintsUsedByList().',
            );
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

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

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }

        let urlPath = `/managed/blueprints/{instance_uuid}/used_by/`;
        urlPath = urlPath.replace(
            `{${"instance_uuid"}}`,
            encodeURIComponent(String(requestParameters["instanceUuid"])),
        );

        return {
            path: urlPath,
            method: "GET",
            headers: headerParameters,
            query: queryParameters,
        };
    }

    /**
     * Get a list of all objects that use this object
     */
    async managedBlueprintsUsedByListRaw(
        requestParameters: ManagedBlueprintsUsedByListRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Array<UsedBy>>> {
        const requestOptions = await this.managedBlueprintsUsedByListRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Get a list of all objects that use this object
     */
    async managedBlueprintsUsedByList(
        requestParameters: ManagedBlueprintsUsedByListRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Array<UsedBy>> {
        const response = await this.managedBlueprintsUsedByListRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }
}
