import _ from 'lodash';
import topTeams from 'javascript/top/teams'

const LINKEDIN_URL = 'https://www.linkedin.com/in/marekgrzybek';
const GITHUB_URL = 'https://github.com/feimosi';
const TWITTER_URL = 'https://twitter.com/feimosi';

const skillset = {
    advanced: ['JS', 'Angular', 'Git'],
    intermediate: ['ES2015+', 'Web APIs', 'HTML5', 'jQuery', 'lodash'],
    general: ['Backbone', 'Express', 'MongoDB']
}

function *allSkillsGenerator() {
    const skills = _.chain(skillset).values().flatten().value().sort();
    for (let skill of skills)
        yield skill;
}

function getMoreInfo() {
    const linkedinPromise = fetch(LINKEDIN_URL);
    const githubPromise = fetch(GITHUB_URL);
    return Promise.all([linkedinPromise, githubPromise])
                  .then( (resolves) => resolves.map( (result) => result.data) );
}

function validateOffer(offer) {
    if (offer.support.IE < 11) {
        throw new Error('☢ Dinosaurs Not Supported Exception ☢');
    }
    const onlySeriousVCS = /git/i;
    const deprecated = /(grunt|jshint)/i;
    return offer.vcs.match(onlySeriousVCS) 
        && !offer.tools.match(deprecated)
        && topTeams.includes(offer.team);
}

export default {
    allSkillsGenerator,
    getMoreInfo,
    validateOffer
}