const fetch = require("node-fetch");


const Client = {
    headers: {        
        'authority' : 'www.amazon.com',
        'method' : 'GET',
        'path' : '',
        'scheme' : 'https',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
        'accept-encoding' : 'gzip, deflate, br',
        'accept-language' : 'ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7',
        'cache-control' : 'max-age=0',
        'sec-fetch-mode' : 'navigate',
        'sec-fetch-site' : 'none',
        'sec-fetch-user' : '?1',
        'upgrade-insecure-requests' : '1',
        'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36',
        cookie: 'lc-main=ko_KR;i18n-prefs=KRW'
    },
    request: async (args) => {
        let url = Client[args.call](args)
        Client.headers['path'] = url.replace(args.amazon.us.data.url, '')
        return fetch(url, { headers: Client.headers }).then(res => res.textConverted());
    },
    offerListing: (args) => {
        let url = args.amazon.us.data.url + '/dp/offer-listing/' + args.asin + '/ref=dp_olp_new_mbc?ie=UTF8&condition=new';
        console.log('- request product offer listing page url : ' + url);
        return url;
    },
    productDetail: (args) => {
        let url = args.amazon.us.data.url + '/' + args.amazon.us.utils.fakeTitle(7, 4, '') + '/dp/' + args.asin;
        console.log('- request product detail page url : ' + url);
        return url;
    },
    categories: (args) => {
        let url = args.amazon.us.data.url + '/gp/site-directory';
        console.log('- request category page url : ' + url)
        return url;
    },
    subCategories: (args) => {
        let url = args.amazon.us.data.url + args.category.link;
        console.log('- request sub category page url : ' + url)
        return url;
    },
    productLinks: (args) => {
        let url = args.amazon.us.data.url + args.link;
        console.log('- request product links page url : ' + url)
        return url;
    }
}

module.exports = Client;