/* 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 {
    LifecycleIteration,
    LifecycleIterationRequest,
    LifecycleRule,
    LifecycleRuleRequest,
    PaginatedLifecycleIterationList,
    PaginatedLifecycleRuleList,
    PatchedLifecycleRuleRequest,
    Review,
    ReviewRequest,
} from "../models/index";
import {
    LifecycleIterationFromJSON,
    LifecycleIterationRequestToJSON,
    LifecycleRuleFromJSON,
    LifecycleRuleRequestToJSON,
    PaginatedLifecycleIterationListFromJSON,
    PaginatedLifecycleRuleListFromJSON,
    PatchedLifecycleRuleRequestToJSON,
    ReviewFromJSON,
    ReviewRequestToJSON,
} from "../models/index";
import * as runtime from "../runtime";

export interface LifecycleIterationsCreateRequest {
    lifecycleIterationRequest: LifecycleIterationRequest;
}

export interface LifecycleIterationsLatestRetrieveRequest {
    contentType: string;
    objectId: string;
}

export interface LifecycleIterationsListOpenRequest {
    ordering?: string;
    page?: number;
    pageSize?: number;
    search?: string;
    userIsReviewer?: boolean;
}

export interface LifecycleReviewsCreateRequest {
    reviewRequest: ReviewRequest;
}

export interface LifecycleRulesCreateRequest {
    lifecycleRuleRequest: LifecycleRuleRequest;
}

export interface LifecycleRulesDestroyRequest {
    id: string;
}

export interface LifecycleRulesListRequest {
    contentTypeModel?: string;
    ordering?: string;
    page?: number;
    pageSize?: number;
    search?: string;
}

export interface LifecycleRulesPartialUpdateRequest {
    id: string;
    patchedLifecycleRuleRequest?: PatchedLifecycleRuleRequest;
}

export interface LifecycleRulesRetrieveRequest {
    id: string;
}

export interface LifecycleRulesUpdateRequest {
    id: string;
    lifecycleRuleRequest: LifecycleRuleRequest;
}

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

        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 = `/lifecycle/iterations/`;

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleIterationsCreateRaw(
        requestParameters: LifecycleIterationsCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<LifecycleIteration>> {
        const requestOptions = await this.lifecycleIterationsCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleIterationsCreate(
        requestParameters: LifecycleIterationsCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<LifecycleIteration> {
        const response = await this.lifecycleIterationsCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

        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 = `/lifecycle/iterations/latest/{content_type}/{object_id}/`;
        urlPath = urlPath.replace(
            `{${"content_type"}}`,
            encodeURIComponent(String(requestParameters["contentType"])),
        );
        urlPath = urlPath.replace(
            `{${"object_id"}}`,
            encodeURIComponent(String(requestParameters["objectId"])),
        );

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleIterationsLatestRetrieveRaw(
        requestParameters: LifecycleIterationsLatestRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<LifecycleIteration>> {
        const requestOptions =
            await this.lifecycleIterationsLatestRetrieveRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleIterationsLatestRetrieve(
        requestParameters: LifecycleIterationsLatestRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<LifecycleIteration> {
        const response = await this.lifecycleIterationsLatestRetrieveRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

    /**
     * Creates request options for lifecycleIterationsListOpen without sending the request
     */
    async lifecycleIterationsListOpenRequestOpts(
        requestParameters: LifecycleIterationsListOpenRequest,
    ): Promise<runtime.RequestOpts> {
        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["search"] != null) {
            queryParameters["search"] = requestParameters["search"];
        }

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

        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 = `/lifecycle/iterations/open/`;

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleIterationsListOpenRaw(
        requestParameters: LifecycleIterationsListOpenRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<PaginatedLifecycleIterationList>> {
        const requestOptions = await this.lifecycleIterationsListOpenRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleIterationsListOpen(
        requestParameters: LifecycleIterationsListOpenRequest = {},
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<PaginatedLifecycleIterationList> {
        const response = await this.lifecycleIterationsListOpenRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

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

        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 = `/lifecycle/reviews/`;

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleReviewsCreateRaw(
        requestParameters: LifecycleReviewsCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Review>> {
        const requestOptions = await this.lifecycleReviewsCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Mixin to validate that a valid enterprise license exists before allowing to save the object
     */
    async lifecycleReviewsCreate(
        requestParameters: LifecycleReviewsCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Review> {
        const response = await this.lifecycleReviewsCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

        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 = `/lifecycle/rules/`;

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

    /**
     */
    async lifecycleRulesCreateRaw(
        requestParameters: LifecycleRulesCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<LifecycleRule>> {
        const requestOptions = await this.lifecycleRulesCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async lifecycleRulesCreate(
        requestParameters: LifecycleRulesCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<LifecycleRule> {
        const response = await this.lifecycleRulesCreateRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

    /**
     */
    async lifecycleRulesDestroyRaw(
        requestParameters: LifecycleRulesDestroyRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<void>> {
        const requestOptions = await this.lifecycleRulesDestroyRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     */
    async lifecycleRulesDestroy(
        requestParameters: LifecycleRulesDestroyRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<void> {
        await this.lifecycleRulesDestroyRaw(requestParameters, initOverrides);
    }

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

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

        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["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 = `/lifecycle/rules/`;

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

    /**
     */
    async lifecycleRulesListRaw(
        requestParameters: LifecycleRulesListRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<PaginatedLifecycleRuleList>> {
        const requestOptions = await this.lifecycleRulesListRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async lifecycleRulesList(
        requestParameters: LifecycleRulesListRequest = {},
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<PaginatedLifecycleRuleList> {
        const response = await this.lifecycleRulesListRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

    /**
     */
    async lifecycleRulesPartialUpdateRaw(
        requestParameters: LifecycleRulesPartialUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<LifecycleRule>> {
        const requestOptions = await this.lifecycleRulesPartialUpdateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async lifecycleRulesPartialUpdate(
        requestParameters: LifecycleRulesPartialUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<LifecycleRule> {
        const response = await this.lifecycleRulesPartialUpdateRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

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

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

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

    /**
     */
    async lifecycleRulesRetrieveRaw(
        requestParameters: LifecycleRulesRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<LifecycleRule>> {
        const requestOptions = await this.lifecycleRulesRetrieveRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async lifecycleRulesRetrieve(
        requestParameters: LifecycleRulesRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<LifecycleRule> {
        const response = await this.lifecycleRulesRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

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

    /**
     */
    async lifecycleRulesUpdateRaw(
        requestParameters: LifecycleRulesUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<LifecycleRule>> {
        const requestOptions = await this.lifecycleRulesUpdateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async lifecycleRulesUpdate(
        requestParameters: LifecycleRulesUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<LifecycleRule> {
        const response = await this.lifecycleRulesUpdateRaw(requestParameters, initOverrides);
        return await response.value();
    }
}
