/* tslint:disable */
/* eslint-disable */
/**
 * authentik
 * Making authentication simple.
 *
 * The version of the OpenAPI document: 2026.2.0-rc4
 * 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 {
  GenericError,
  LifecycleIteration,
  LifecycleIterationRequest,
  LifecycleRule,
  LifecycleRuleRequest,
  PaginatedLifecycleIterationList,
  PaginatedLifecycleRuleList,
  PatchedLifecycleRuleRequest,
  Review,
  ReviewRequest,
  ValidationError,
} from '../models/index';
import {
    GenericErrorFromJSON,
    GenericErrorToJSON,
    LifecycleIterationFromJSON,
    LifecycleIterationToJSON,
    LifecycleIterationRequestFromJSON,
    LifecycleIterationRequestToJSON,
    LifecycleRuleFromJSON,
    LifecycleRuleToJSON,
    LifecycleRuleRequestFromJSON,
    LifecycleRuleRequestToJSON,
    PaginatedLifecycleIterationListFromJSON,
    PaginatedLifecycleIterationListToJSON,
    PaginatedLifecycleRuleListFromJSON,
    PaginatedLifecycleRuleListToJSON,
    PatchedLifecycleRuleRequestFromJSON,
    PatchedLifecycleRuleRequestToJSON,
    ReviewFromJSON,
    ReviewToJSON,
    ReviewRequestFromJSON,
    ReviewRequestToJSON,
    ValidationErrorFromJSON,
    ValidationErrorToJSON,
} from '../models/index';

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 {

    /**
     * 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>> {
        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/`;

        const response = await this.request({
            path: urlPath,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: LifecycleIterationRequestToJSON(requestParameters['lifecycleIterationRequest']),
        }, 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();
    }

    /**
     * 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>> {
        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'])));

        const response = await this.request({
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, 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();
    }

    /**
     * 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 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/`;

        const response = await this.request({
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, 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();
    }

    /**
     * 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>> {
        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/`;

        const response = await this.request({
            path: urlPath,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: ReviewRequestToJSON(requestParameters['reviewRequest']),
        }, 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();
    }

    /**
     */
    async lifecycleRulesCreateRaw(requestParameters: LifecycleRulesCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LifecycleRule>> {
        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/`;

        const response = await this.request({
            path: urlPath,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: LifecycleRuleRequestToJSON(requestParameters['lifecycleRuleRequest']),
        }, 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();
    }

    /**
     */
    async lifecycleRulesDestroyRaw(requestParameters: LifecycleRulesDestroyRequest, 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 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'])));

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

        return new runtime.VoidApiResponse(response);
    }

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

    /**
     */
    async lifecycleRulesListRaw(requestParameters: LifecycleRulesListRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<PaginatedLifecycleRuleList>> {
        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/`;

        const response = await this.request({
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, 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();
    }

    /**
     */
    async lifecycleRulesPartialUpdateRaw(requestParameters: LifecycleRulesPartialUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LifecycleRule>> {
        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'])));

        const response = await this.request({
            path: urlPath,
            method: 'PATCH',
            headers: headerParameters,
            query: queryParameters,
            body: PatchedLifecycleRuleRequestToJSON(requestParameters['patchedLifecycleRuleRequest']),
        }, 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();
    }

    /**
     */
    async lifecycleRulesRetrieveRaw(requestParameters: LifecycleRulesRetrieveRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LifecycleRule>> {
        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'])));

        const response = await this.request({
            path: urlPath,
            method: 'GET',
            headers: headerParameters,
            query: queryParameters,
        }, 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();
    }

    /**
     */
    async lifecycleRulesUpdateRaw(requestParameters: LifecycleRulesUpdateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<LifecycleRule>> {
        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'])));

        const response = await this.request({
            path: urlPath,
            method: 'PUT',
            headers: headerParameters,
            query: queryParameters,
            body: LifecycleRuleRequestToJSON(requestParameters['lifecycleRuleRequest']),
        }, 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();
    }

}
