/* tslint:disable */
/* eslint-disable */
/**
 * authentik
 * Making authentication simple.
 *
 * The version of the OpenAPI document: 2025.10.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 {
  GenericError,
  PaginatedScheduleList,
  PaginatedTaskList,
  PatchedScheduleRequest,
  Schedule,
  ScheduleRequest,
  Task,
  ValidationError,
  Worker,
} from '../models/index';
import {
    GenericErrorFromJSON,
    GenericErrorToJSON,
    PaginatedScheduleListFromJSON,
    PaginatedScheduleListToJSON,
    PaginatedTaskListFromJSON,
    PaginatedTaskListToJSON,
    PatchedScheduleRequestFromJSON,
    PatchedScheduleRequestToJSON,
    ScheduleFromJSON,
    ScheduleToJSON,
    ScheduleRequestFromJSON,
    ScheduleRequestToJSON,
    TaskFromJSON,
    TaskToJSON,
    ValidationErrorFromJSON,
    ValidationErrorToJSON,
    WorkerFromJSON,
    WorkerToJSON,
} from '../models/index';

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<TasksTasksListAggregatedStatusEnum>;
    ordering?: string;
    page?: number;
    pageSize?: number;
    queueName?: string;
    relObjContentTypeAppLabel?: string;
    relObjContentTypeModel?: string;
    relObjId?: string;
    relObjIdIsnull?: boolean;
    search?: string;
    state?: TasksTasksListStateEnum;
}

export interface TasksTasksRetrieveRequest {
    messageId: string;
}

export interface TasksTasksRetryCreateRequest {
    messageId: string;
}

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

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

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

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

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

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

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

    /**
     * Trigger this schedule now
     */
    async tasksSchedulesSendCreateRaw(requestParameters: TasksSchedulesSendCreateRequest, 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 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'])));

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

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

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

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

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

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

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

    /**
     * Retry task
     */
    async tasksTasksRetryCreateRaw(requestParameters: TasksTasksRetryCreateRequest, initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<void>> {
        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'])));

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

        return new runtime.VoidApiResponse(response);
    }

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

    /**
     * Get currently connected worker count.
     */
    async tasksWorkersListRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<Worker>>> {
        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`;

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

}

/**
 * @export
 */
export const TasksTasksListAggregatedStatusEnum = {
    Consumed: 'consumed',
    Done: 'done',
    Error: 'error',
    Info: 'info',
    Queued: 'queued',
    Rejected: 'rejected',
    Warning: 'warning',
    UnknownDefaultOpenApi: '11184809'
} as const;
export type TasksTasksListAggregatedStatusEnum = typeof TasksTasksListAggregatedStatusEnum[keyof typeof TasksTasksListAggregatedStatusEnum];
/**
 * @export
 */
export const TasksTasksListStateEnum = {
    Consumed: 'consumed',
    Done: 'done',
    Queued: 'queued',
    Rejected: 'rejected',
    UnknownDefaultOpenApi: '11184809'
} as const;
export type TasksTasksListStateEnum = typeof TasksTasksListStateEnum[keyof typeof TasksTasksListStateEnum];
