/* tslint:disable */
/* eslint-disable */
/**
 * authentik
 * Making authentication simple.
 *
 * The version of the OpenAPI document: 2025.12.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 {
  ExpiringBaseGrantModel,
  GenericError,
  PaginatedExpiringBaseGrantModelList,
  PaginatedTokenModelList,
  TokenModel,
  UsedBy,
  ValidationError,
} from '../models/index';
import {
    ExpiringBaseGrantModelFromJSON,
    ExpiringBaseGrantModelToJSON,
    GenericErrorFromJSON,
    GenericErrorToJSON,
    PaginatedExpiringBaseGrantModelListFromJSON,
    PaginatedExpiringBaseGrantModelListToJSON,
    PaginatedTokenModelListFromJSON,
    PaginatedTokenModelListToJSON,
    TokenModelFromJSON,
    TokenModelToJSON,
    UsedByFromJSON,
    UsedByToJSON,
    ValidationErrorFromJSON,
    ValidationErrorToJSON,
} from '../models/index';

export interface Oauth2AccessTokensDestroyRequest {
    id: number;
}

export interface Oauth2AccessTokensListRequest {
    ordering?: string;
    page?: number;
    pageSize?: number;
    provider?: number;
    search?: string;
    user?: number;
}

export interface Oauth2AccessTokensRetrieveRequest {
    id: number;
}

export interface Oauth2AccessTokensUsedByListRequest {
    id: number;
}

export interface Oauth2AuthorizationCodesDestroyRequest {
    id: number;
}

export interface Oauth2AuthorizationCodesListRequest {
    ordering?: string;
    page?: number;
    pageSize?: number;
    provider?: number;
    search?: string;
    user?: number;
}

export interface Oauth2AuthorizationCodesRetrieveRequest {
    id: number;
}

export interface Oauth2AuthorizationCodesUsedByListRequest {
    id: number;
}

export interface Oauth2RefreshTokensDestroyRequest {
    id: number;
}

export interface Oauth2RefreshTokensListRequest {
    ordering?: string;
    page?: number;
    pageSize?: number;
    provider?: number;
    search?: string;
    user?: number;
}

export interface Oauth2RefreshTokensRetrieveRequest {
    id: number;
}

export interface Oauth2RefreshTokensUsedByListRequest {
    id: number;
}

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

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

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

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

        return new runtime.VoidApiResponse(response);
    }

    /**
     * AccessToken Viewset
     */
    async oauth2AccessTokensDestroy(requestParameters: Oauth2AccessTokensDestroyRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.oauth2AccessTokensDestroyRaw(requestParameters, initOverrides);
    }

    /**
     * AccessToken Viewset
     */
    async oauth2AccessTokensListRaw(requestParameters: Oauth2AccessTokensListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaginatedTokenModelList>> {
        const queryParameters: any = {};

        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['provider'] != null) {
            queryParameters['provider'] = requestParameters['provider'];
        }

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

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

        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 = `/oauth2/access_tokens/`;

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

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

    /**
     * AccessToken Viewset
     */
    async oauth2AccessTokensList(requestParameters: Oauth2AccessTokensListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaginatedTokenModelList> {
        const response = await this.oauth2AccessTokensListRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

        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 = `/oauth2/access_tokens/{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) => TokenModelFromJSON(jsonValue));
    }

    /**
     * AccessToken Viewset
     */
    async oauth2AccessTokensRetrieve(requestParameters: Oauth2AccessTokensRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenModel> {
        const response = await this.oauth2AccessTokensRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get a list of all objects that use this object
     */
    async oauth2AccessTokensUsedByListRaw(requestParameters: Oauth2AccessTokensUsedByListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<UsedBy>>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling oauth2AccessTokensUsedByList().'
            );
        }

        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 = `/oauth2/access_tokens/{id}/used_by/`;
        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) => jsonValue.map(UsedByFromJSON));
    }

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

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

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

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

        return new runtime.VoidApiResponse(response);
    }

    /**
     * AuthorizationCode Viewset
     */
    async oauth2AuthorizationCodesDestroy(requestParameters: Oauth2AuthorizationCodesDestroyRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.oauth2AuthorizationCodesDestroyRaw(requestParameters, initOverrides);
    }

    /**
     * AuthorizationCode Viewset
     */
    async oauth2AuthorizationCodesListRaw(requestParameters: Oauth2AuthorizationCodesListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaginatedExpiringBaseGrantModelList>> {
        const queryParameters: any = {};

        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['provider'] != null) {
            queryParameters['provider'] = requestParameters['provider'];
        }

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

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

        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 = `/oauth2/authorization_codes/`;

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

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

    /**
     * AuthorizationCode Viewset
     */
    async oauth2AuthorizationCodesList(requestParameters: Oauth2AuthorizationCodesListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaginatedExpiringBaseGrantModelList> {
        const response = await this.oauth2AuthorizationCodesListRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

        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 = `/oauth2/authorization_codes/{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) => ExpiringBaseGrantModelFromJSON(jsonValue));
    }

    /**
     * AuthorizationCode Viewset
     */
    async oauth2AuthorizationCodesRetrieve(requestParameters: Oauth2AuthorizationCodesRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<ExpiringBaseGrantModel> {
        const response = await this.oauth2AuthorizationCodesRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get a list of all objects that use this object
     */
    async oauth2AuthorizationCodesUsedByListRaw(requestParameters: Oauth2AuthorizationCodesUsedByListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<UsedBy>>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling oauth2AuthorizationCodesUsedByList().'
            );
        }

        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 = `/oauth2/authorization_codes/{id}/used_by/`;
        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) => jsonValue.map(UsedByFromJSON));
    }

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

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

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

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

        return new runtime.VoidApiResponse(response);
    }

    /**
     * RefreshToken Viewset
     */
    async oauth2RefreshTokensDestroy(requestParameters: Oauth2RefreshTokensDestroyRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<void> {
        await this.oauth2RefreshTokensDestroyRaw(requestParameters, initOverrides);
    }

    /**
     * RefreshToken Viewset
     */
    async oauth2RefreshTokensListRaw(requestParameters: Oauth2RefreshTokensListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaginatedTokenModelList>> {
        const queryParameters: any = {};

        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['provider'] != null) {
            queryParameters['provider'] = requestParameters['provider'];
        }

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

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

        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 = `/oauth2/refresh_tokens/`;

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

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

    /**
     * RefreshToken Viewset
     */
    async oauth2RefreshTokensList(requestParameters: Oauth2RefreshTokensListRequest = {}, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<PaginatedTokenModelList> {
        const response = await this.oauth2RefreshTokensListRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

        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 = `/oauth2/refresh_tokens/{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) => TokenModelFromJSON(jsonValue));
    }

    /**
     * RefreshToken Viewset
     */
    async oauth2RefreshTokensRetrieve(requestParameters: Oauth2RefreshTokensRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<TokenModel> {
        const response = await this.oauth2RefreshTokensRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

    /**
     * Get a list of all objects that use this object
     */
    async oauth2RefreshTokensUsedByListRaw(requestParameters: Oauth2RefreshTokensUsedByListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<UsedBy>>> {
        if (requestParameters['id'] == null) {
            throw new runtime.RequiredError(
                'id',
                'Required parameter "id" was null or undefined when calling oauth2RefreshTokensUsedByList().'
            );
        }

        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 = `/oauth2/refresh_tokens/{id}/used_by/`;
        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) => jsonValue.map(UsedByFromJSON));
    }

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

}
