/* 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 {
    GlobalTaskStatus,
    PaginatedScheduleList,
    PaginatedTaskList,
    PatchedScheduleRequest,
    Schedule,
    ScheduleRequest,
    Task,
    TaskAggregatedStatusEnum,
    TaskStatusEnum,
    Worker,
} from "../models/index";
import {
    GlobalTaskStatusFromJSON,
    PaginatedScheduleListFromJSON,
    PaginatedTaskListFromJSON,
    PatchedScheduleRequestToJSON,
    ScheduleFromJSON,
    ScheduleRequestToJSON,
    TaskFromJSON,
    WorkerFromJSON,
} from "../models/index";
import * as runtime from "../runtime";

export interface TasksSchedulesListRequest {
    actorName?: string;
    ordering?: string;
    page?: number;
    pageSize?: number;
    paused?: boolean;
    relObjContentTypeAppLabel?: string;
    relObjContentTypeModel?: string;
    relObjId?: string;
    relObjIdIsnull?: boolean;
    search?: string;
}

export interface TasksSchedulesPartialUpdateRequest {
    id: string;
    patchedScheduleRequest?: PatchedScheduleRequest;
}

export interface TasksSchedulesRetrieveRequest {
    id: string;
}

export interface TasksSchedulesSendCreateRequest {
    id: string;
}

export interface TasksSchedulesUpdateRequest {
    id: string;
    scheduleRequest: ScheduleRequest;
}

export interface TasksTasksListRequest {
    actorName?: string;
    aggregatedStatus?: Array<TaskAggregatedStatusEnum>;
    ordering?: string;
    page?: number;
    pageSize?: number;
    queueName?: string;
    relObjContentTypeAppLabel?: string;
    relObjContentTypeModel?: string;
    relObjId?: string;
    relObjIdIsnull?: boolean;
    search?: string;
    state?: TaskStatusEnum;
}

export interface TasksTasksRetrieveRequest {
    messageId: string;
}

export interface TasksTasksRetryCreateRequest {
    messageId: string;
}

/**
 *
 */
export class TasksApi extends runtime.BaseAPI {
    /**
     * Creates request options for tasksSchedulesList without sending the request
     */
    async tasksSchedulesListRequestOpts(
        requestParameters: TasksSchedulesListRequest,
    ): Promise<runtime.RequestOpts> {
        const queryParameters: any = {};

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

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

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

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

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

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

        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 = `/tasks/schedules/`;

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

    /**
     */
    async tasksSchedulesListRaw(
        requestParameters: TasksSchedulesListRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<PaginatedScheduleList>> {
        const requestOptions = await this.tasksSchedulesListRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async tasksSchedulesList(
        requestParameters: TasksSchedulesListRequest = {},
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<PaginatedScheduleList> {
        const response = await this.tasksSchedulesListRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

    /**
     */
    async tasksSchedulesPartialUpdateRaw(
        requestParameters: TasksSchedulesPartialUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Schedule>> {
        const requestOptions = await this.tasksSchedulesPartialUpdateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async tasksSchedulesPartialUpdate(
        requestParameters: TasksSchedulesPartialUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Schedule> {
        const response = await this.tasksSchedulesPartialUpdateRaw(
            requestParameters,
            initOverrides,
        );
        return await response.value();
    }

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

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

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

    /**
     */
    async tasksSchedulesRetrieveRaw(
        requestParameters: TasksSchedulesRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Schedule>> {
        const requestOptions = await this.tasksSchedulesRetrieveRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async tasksSchedulesRetrieve(
        requestParameters: TasksSchedulesRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Schedule> {
        const response = await this.tasksSchedulesRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

    /**
     * Trigger this schedule now
     */
    async tasksSchedulesSendCreateRaw(
        requestParameters: TasksSchedulesSendCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<void>> {
        const requestOptions = await this.tasksSchedulesSendCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Trigger this schedule now
     */
    async tasksSchedulesSendCreate(
        requestParameters: TasksSchedulesSendCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<void> {
        await this.tasksSchedulesSendCreateRaw(requestParameters, initOverrides);
    }

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

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

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

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

    /**
     */
    async tasksSchedulesUpdateRaw(
        requestParameters: TasksSchedulesUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Schedule>> {
        const requestOptions = await this.tasksSchedulesUpdateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async tasksSchedulesUpdate(
        requestParameters: TasksSchedulesUpdateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Schedule> {
        const response = await this.tasksSchedulesUpdateRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

        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["queueName"] != null) {
            queryParameters["queue_name"] = requestParameters["queueName"];
        }

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

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

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

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

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

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

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

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

    /**
     */
    async tasksTasksListRaw(
        requestParameters: TasksTasksListRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<PaginatedTaskList>> {
        const requestOptions = await this.tasksTasksListRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async tasksTasksList(
        requestParameters: TasksTasksListRequest = {},
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<PaginatedTaskList> {
        const response = await this.tasksTasksListRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

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

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

    /**
     */
    async tasksTasksRetrieveRaw(
        requestParameters: TasksTasksRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Task>> {
        const requestOptions = await this.tasksTasksRetrieveRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     */
    async tasksTasksRetrieve(
        requestParameters: TasksTasksRetrieveRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Task> {
        const response = await this.tasksTasksRetrieveRaw(requestParameters, initOverrides);
        return await response.value();
    }

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

        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 = `/tasks/tasks/{message_id}/retry/`;
        urlPath = urlPath.replace(
            `{${"message_id"}}`,
            encodeURIComponent(String(requestParameters["messageId"])),
        );

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

    /**
     * Retry task
     */
    async tasksTasksRetryCreateRaw(
        requestParameters: TasksTasksRetryCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<void>> {
        const requestOptions = await this.tasksTasksRetryCreateRequestOpts(requestParameters);
        const response = await this.request(requestOptions, initOverrides);

        return new runtime.VoidApiResponse(response);
    }

    /**
     * Retry task
     */
    async tasksTasksRetryCreate(
        requestParameters: TasksTasksRetryCreateRequest,
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<void> {
        await this.tasksTasksRetryCreateRaw(requestParameters, initOverrides);
    }

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

        const headerParameters: runtime.HTTPHeaders = {};

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

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

        let urlPath = `/tasks/tasks/status/`;

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

    /**
     * Global status summary for all tasks
     */
    async tasksTasksStatusRetrieveRaw(
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<GlobalTaskStatus>> {
        const requestOptions = await this.tasksTasksStatusRetrieveRequestOpts();
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Global status summary for all tasks
     */
    async tasksTasksStatusRetrieve(
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<GlobalTaskStatus> {
        const response = await this.tasksTasksStatusRetrieveRaw(initOverrides);
        return await response.value();
    }

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

        const headerParameters: runtime.HTTPHeaders = {};

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

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

        let urlPath = `/tasks/workers/`;

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

    /**
     * Get currently connected worker count.
     */
    async tasksWorkersListRaw(
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<runtime.ApiResponse<Array<Worker>>> {
        const requestOptions = await this.tasksWorkersListRequestOpts();
        const response = await this.request(requestOptions, initOverrides);

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

    /**
     * Get currently connected worker count.
     */
    async tasksWorkersList(
        initOverrides?: RequestInit | runtime.InitOverrideFunction,
    ): Promise<Array<Worker>> {
        const response = await this.tasksWorkersListRaw(initOverrides);
        return await response.value();
    }
}
