const { mq } = require('./mqPrefix')

/** JKES 乐跑任务队列（与主分支 runforge_task_queue 隔离，支持 mqPrefix） */
const TASK_QUEUE = mq('jkes_runforge_task_queue')

async function assertRunforgeTaskIngress(channel, logger) {
    await channel.assertQueue(TASK_QUEUE, { durable: true })
    return { mode: 'direct', queue: TASK_QUEUE }
}

function publishRunforgeTask(channel, messageObject) {
    const body = Buffer.from(JSON.stringify(messageObject))
    channel.sendToQueue(TASK_QUEUE, body, {
        persistent: true,
        contentType: 'application/json'
    })
}

module.exports = {
    TASK_QUEUE,
    assertRunforgeTaskIngress,
    publishRunforgeTask
}
