import { createLocalReq } from '../index.js';
import { runJobs } from './operations/runJobs/index.js';
export const getJobsLocalAPI = (payload)=>({
        queue: async (args)=>{
            let queue;
            // If user specifies queue, use that
            if (args.queue) {
                queue = args.queue;
            } else if (args.workflow) {
                // Otherwise, if there is a workflow specified, and it has a default queue to use,
                // use that
                const workflow = payload.config.jobs?.workflows?.find(({ slug })=>slug === args.workflow);
                if (workflow?.queue) {
                    queue = workflow.queue;
                }
            }
            return await payload.create({
                collection: 'payload-jobs',
                data: {
                    input: args.input,
                    queue,
                    taskSlug: 'task' in args ? args.task : undefined,
                    workflowSlug: 'workflow' in args ? args.workflow : undefined
                },
                req: args.req
            });
        // Type assertion is still needed here
        },
        run: async (args)=>{
            const newReq = args?.req ?? await createLocalReq({}, payload);
            const result = await runJobs({
                limit: args?.limit,
                overrideAccess: args?.overrideAccess !== false,
                queue: args?.queue,
                req: newReq
            });
            return result;
        }
    });

//# sourceMappingURL=localAPI.js.map