/* tslint:disable */
/* eslint-disable */
/**
 * authentik
 * Making authentication simple.
 *
 * The version of the OpenAPI document: 2026.2.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 * as runtime from '../runtime';
import type {
  App,
  FileList,
  GenericError,
  PatchedSettingsRequest,
  Settings,
  SettingsRequest,
  SystemInfo,
  UsedBy,
  ValidationError,
  Version,
  VersionHistory,
} from '../models/index';
import {
    AppFromJSON,
    AppToJSON,
    FileListFromJSON,
    FileListToJSON,
    GenericErrorFromJSON,
    GenericErrorToJSON,
    PatchedSettingsRequestFromJSON,
    PatchedSettingsRequestToJSON,
    SettingsFromJSON,
    SettingsToJSON,
    SettingsRequestFromJSON,
    SettingsRequestToJSON,
    SystemInfoFromJSON,
    SystemInfoToJSON,
    UsedByFromJSON,
    UsedByToJSON,
    ValidationErrorFromJSON,
    ValidationErrorToJSON,
    VersionFromJSON,
    VersionToJSON,
    VersionHistoryFromJSON,
    VersionHistoryToJSON,
} from '../models/index';

export interface AdminFileCreateRequest {
    file: Blob;
    name?: string;
    usage?: string;
}

export interface AdminFileDestroyRequest {
    name?: string;
    usage?: AdminFileDestroyUsageEnum;
}

export interface AdminFileListRequest {
    manageableOnly?: boolean;
    search?: string;
    usage?: AdminFileListUsageEnum;
}

export interface AdminFileUsedByListRequest {
    name?: string;
}

export interface AdminSettingsPartialUpdateRequest {
    patchedSettingsRequest?: PatchedSettingsRequest;
}

export interface AdminSettingsUpdateRequest {
    settingsRequest: SettingsRequest;
}

export interface AdminVersionHistoryListRequest {
    build?: string;
    ordering?: string;
    search?: string;
    version?: string;
}

export interface AdminVersionHistoryRetrieveRequest {
    id: number;
}

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

    /**
     * Read-only view list all installed apps
     */
    async adminAppsListRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<App>>> {
        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 = `/admin/apps/`;

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

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

    /**
     * Read-only view list all installed apps
     */
    async adminAppsList(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<App>> {
        const response = await this.adminAppsListRaw(initOverrides);
        return await response.value();
    }

    /**
     * Upload file to storage backend.
     */
    async adminFileCreateRaw(requestParameters: AdminFileCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        if (requestParameters['file'] == null) {
            throw new runtime.RequiredError(
                'file',
                'Required parameter "file" was null or undefined when calling adminFileCreate().'
            );
        }

        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['name'] != null) {
            formParams.append('name', requestParameters['name'] as any);
        }

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


        let urlPath = `/admin/file/`;

        const response = await this.request({
            path: urlPath,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Upload file to storage backend.
     */
    async adminFileCreate(requestParameters: AdminFileCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.adminFileCreateRaw(requestParameters, initOverrides);
    }

    /**
     * Delete file from storage backend.
     */
    async adminFileDestroyRaw(requestParameters: AdminFileDestroyRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        const queryParameters: any = {};

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

        if (requestParameters['usage'] != null) {
            queryParameters['usage'] = requestParameters['usage'];
        }

        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 = `/admin/file/`;

        const response = await this.request({
            path: urlPath,
            method: 'DELETE',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Delete file from storage backend.
     */
    async adminFileDestroy(requestParameters: AdminFileDestroyRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.adminFileDestroyRaw(requestParameters, initOverrides);
    }

    /**
     * List files from storage backend.
     */
    async adminFileListRaw(requestParameters: AdminFileListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<FileList>>> {
        const queryParameters: any = {};

        if (requestParameters['manageableOnly'] != null) {
            queryParameters['manageable_only'] = requestParameters['manageableOnly'];
        }

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

        if (requestParameters['usage'] != null) {
            queryParameters['usage'] = requestParameters['usage'];
        }

        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 = `/admin/file/`;

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

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

    /**
     * List files from storage backend.
     */
    async adminFileList(requestParameters: AdminFileListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<FileList>> {
        const response = await this.adminFileListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     */
    async adminFileUsedByListRaw(requestParameters: AdminFileUsedByListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<UsedBy>>> {
        const queryParameters: any = {};

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

        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 = `/admin/file/used_by/`;

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

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

    /**
     */
    async adminFileUsedByList(requestParameters: AdminFileUsedByListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<UsedBy>> {
        const response = await this.adminFileUsedByListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Read-only view list all installed models
     */
    async adminModelsListRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<App>>> {
        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 = `/admin/models/`;

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

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

    /**
     * Read-only view list all installed models
     */
    async adminModelsList(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<App>> {
        const response = await this.adminModelsListRaw(initOverrides);
        return await response.value();
    }

    /**
     * Settings view
     */
    async adminSettingsPartialUpdateRaw(requestParameters: AdminSettingsPartialUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Settings>> {
        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 = `/admin/settings/`;

        const response = await this.request({
            path: urlPath,
            method: 'PATCH',
            headers: headerParameters,
            query: queryParameters,
            body: PatchedSettingsRequestToJSON(requestParameters['patchedSettingsRequest']),
        }, initOverrides);

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

    /**
     * Settings view
     */
    async adminSettingsPartialUpdate(requestParameters: AdminSettingsPartialUpdateRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Settings> {
        const response = await this.adminSettingsPartialUpdateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Settings view
     */
    async adminSettingsRetrieveRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Settings>> {
        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 = `/admin/settings/`;

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

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

    /**
     * Settings view
     */
    async adminSettingsRetrieve(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Settings> {
        const response = await this.adminSettingsRetrieveRaw(initOverrides);
        return await response.value();
    }

    /**
     * Settings view
     */
    async adminSettingsUpdateRaw(requestParameters: AdminSettingsUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Settings>> {
        if (requestParameters['settingsRequest'] == null) {
            throw new runtime.RequiredError(
                'settingsRequest',
                'Required parameter "settingsRequest" was null or undefined when calling adminSettingsUpdate().'
            );
        }

        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 = `/admin/settings/`;

        const response = await this.request({
            path: urlPath,
            method: 'PUT',
            headers: headerParameters,
            query: queryParameters,
            body: SettingsRequestToJSON(requestParameters['settingsRequest']),
        }, initOverrides);

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

    /**
     * Settings view
     */
    async adminSettingsUpdate(requestParameters: AdminSettingsUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Settings> {
        const response = await this.adminSettingsUpdateRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get system information.
     */
    async adminSystemCreateRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SystemInfo>> {
        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 = `/admin/system/`;

        const response = await this.request({
            path: urlPath,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
        }, initOverrides);

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

    /**
     * Get system information.
     */
    async adminSystemCreate(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SystemInfo> {
        const response = await this.adminSystemCreateRaw(initOverrides);
        return await response.value();
    }

    /**
     * Get system information.
     */
    async adminSystemRetrieveRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<SystemInfo>> {
        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 = `/admin/system/`;

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

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

    /**
     * Get system information.
     */
    async adminSystemRetrieve(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<SystemInfo> {
        const response = await this.adminSystemRetrieveRaw(initOverrides);
        return await response.value();
    }

    /**
     * VersionHistory Viewset
     */
    async adminVersionHistoryListRaw(requestParameters: AdminVersionHistoryListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<VersionHistory>>> {
        const queryParameters: any = {};

        if (requestParameters['build'] != null) {
            queryParameters['build'] = requestParameters['build'];
        }

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

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

        if (requestParameters['version'] != null) {
            queryParameters['version'] = requestParameters['version'];
        }

        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 = `/admin/version/history/`;

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

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

    /**
     * VersionHistory Viewset
     */
    async adminVersionHistoryList(requestParameters: AdminVersionHistoryListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Array<VersionHistory>> {
        const response = await this.adminVersionHistoryListRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * VersionHistory Viewset
     */
    async adminVersionHistoryRetrieveRaw(requestParameters: AdminVersionHistoryRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<VersionHistory>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling adminVersionHistoryRetrieve().'
            );
        }

        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 = `/admin/version/history/{id}/`;
        urlPath = urlPath.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters['id'])));

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

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

    /**
     * VersionHistory Viewset
     */
    async adminVersionHistoryRetrieve(requestParameters: AdminVersionHistoryRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<VersionHistory> {
        const response = await this.adminVersionHistoryRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get running and latest version.
     */
    async adminVersionRetrieveRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Version>> {
        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 = `/admin/version/`;

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

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

    /**
     * Get running and latest version.
     */
    async adminVersionRetrieve(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<Version> {
        const response = await this.adminVersionRetrieveRaw(initOverrides);
        return await response.value();
    }

}

/**
 * @export
 */
export const AdminFileDestroyUsageEnum = {
    Media: 'media',
    UnknownDefaultOpenApi: '11184809'
} as const;
export type AdminFileDestroyUsageEnum = typeof AdminFileDestroyUsageEnum[keyof typeof AdminFileDestroyUsageEnum];
/**
 * @export
 */
export const AdminFileListUsageEnum = {
    Media: 'media',
    UnknownDefaultOpenApi: '11184809'
} as const;
export type AdminFileListUsageEnum = typeof AdminFileListUsageEnum[keyof typeof AdminFileListUsageEnum];
