'use strict';

const bhttp = require('bhttp');

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

async function fetchScene(url, site) {
    // const res = await bhttp.get(url);
    const res = await bhttp.get(`https://www.blowpass.com/en/video/${site.id}/${new URL(url).pathname.split('/').slice(-2).join('/')}`);

    const release = await scrapeScene(res.body.toString(), url, site);
    release.channel = release.$('.siteNameSpan')
        .text()
        .trim()
        .toLowerCase()
        .replace('.com', '');

    if (['onlyteenblowjobs.com', 'mommyblowsbest.com'].includes(release.channel)) release.url = url.replace(/video\/\w+\//, 'scene/');
    else release.url = url.replace(/video\/\w+\//, 'video/');

    return release;
}

async function fetchLatest(site, page = 1) {
    const res = await bhttp.get(`https://www.blowpass.com/en/videos/${site.slug}/latest/All-Categories/0/All-Pornstars/0/${page}`);

    return scrapeAll(res.body.toString(), site);
}

async function fetchUpcoming(site) {
    const res = await bhttp.get(`https://www.blowpass.com/en/videos/${site.slug}/upcoming`);

    return scrapeAll(res.body.toString(), site);
}

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