'use strict';

const { getJson, postJson } = require('../../../agent/syncClient');

function push(config, events) {
  return postJson(config, '/api/multibranch-sync/push', { events });
}

function pull(config, options = {}) {
  const params = new URLSearchParams({ limit: String(options.limit || 100), lease_seconds: String(options.leaseSeconds || 60) });
  return getJson(config, `/api/multibranch-sync/pull?${params}`);
}

function ack(config, acknowledgements) {
  return postJson(config, '/api/multibranch-sync/ack', { acknowledgements });
}

function status(config) {
  return getJson(config, '/api/multibranch-sync/status');
}

function conflicts(config, limit = 100) {
  return getJson(config, `/api/multibranch-sync/conflicts?limit=${encodeURIComponent(limit)}`);
}

module.exports = { push, pull, ack, status, conflicts };
