'use strict';

const bhttp = require('bhttp');

const { fetchLatest, fetchUpcoming, scrapeScene, fetchProfile } = require('./gamma');

async function fetchScene(url, site) {
    const res = await bhttp.get(url);

    const release = await scrapeScene(res.body.toString(), url, site);

    const siteDomain = release.$('meta[name="twitter:domain"]').attr('content') || 'allblackx.com'; // only AllBlackX has no twitter domain, no other useful hints available
    const siteSlug = siteDomain && siteDomain.split('.')[0].toLowerCase();
    // const siteUrl = siteDomain && `https://www.${siteDomain}`;

    release.channel = siteSlug;
    release.director = 'Mason';

    return release;
}

function getActorReleasesUrl(actorPath, page = 1) {
    return `https://www.xempire.com/en/videos/xempire/latest/${page}/All-Categories/0${actorPath}`;
}

async function networkFetchProfile(actorName, siteSlug) {
    return fetchProfile(actorName, siteSlug, null, getActorReleasesUrl);
}

module.exports = {
    fetchLatest,
    fetchProfile: networkFetchProfile,
    fetchUpcoming,
    fetchScene,
};
