const CoolifyClient = require('../coolifyClient');

/**
 * List all currently running deployments.
 * @param {string} host_url
 * @param {string} token
 * @returns {Promise<Object[]>}
 * @example
 * list('https://coolify.example.com', 'TOKEN');
 */
async function list(host_url, token) {
  const client = new CoolifyClient(host_url, token);
  return client.get('/api/v1/deployments');
}

/**
 * Get deployment by UUID.
 * @param {string} host_url
 * @param {string} token
 * @param {string} uuid - Deployment UUID
 * @returns {Promise<Object>}
 * @example
 * get('https://coolify.example.com', 'TOKEN', 'deployment-uuid');
 */
async function get(host_url, token, uuid) {
  const client = new CoolifyClient(host_url, token);
  return client.get(`/api/v1/deployments/${uuid}`);
}

/**
 * Deploy by tag or uuid.
 * @param {string} host_url
 * @param {string} token
 * @param {Object} params - { tag, uuid, force }
 * @returns {Promise<Object>}
 * @example
 * deploy('https://coolify.example.com', 'TOKEN', { tag: 'v1.0.0' });
 */
async function deploy(host_url, token, params = {}) {
  const client = new CoolifyClient(host_url, token);
  return client.get('/api/v1/deploy', { params });
}

module.exports = {
  list,
  get,
  deploy,
}; 