const axios = require('../../axios');

/**
 * @param {string} host
 * @param {string} productId
 * @param {string} subProductId
 * @param {string} token
 * @returns {Promise<*>}
 */
async function getContents(host, productId, subProductId, token) {
  try {
    const subProductChunk = subProductId ? `/subproducts/${subProductId}` : '';

    return await axios.get(
      `https://api.${host}/v2/products/${productId}${subProductChunk}/contents`,
      {
        headers: {
          Authorization: `Bearer ${token}`,
          'Content-Type': 'application/json',
        },
      },
    );
  } catch (e) {
    return null;
  }
}

module.exports = getContents;
