'use strict';

const { fetchNetworks, fetchNetworksFromReleases } = require('../networks');

async function fetchNetworksApi(req, res) {
    const networkId = typeof req.params.networkId === 'number' ? req.params.networkId : undefined; // null will literally include NULL results
    const networkSlug = typeof req.params.networkId === 'string' ? req.params.networkId : undefined;

    const networks = await fetchNetworks({
        id: networkId,
        slug: networkSlug,
    });

    res.send(networks);
}

async function fetchNetworksFromReleasesApi(req, res) {
    const networks = await fetchNetworksFromReleases();

    res.send(networks);
}

module.exports = {
    fetchNetworks: fetchNetworksApi,
    fetchNetworksFromReleases: fetchNetworksFromReleasesApi,
};
