/* eslint-env node, mocha */
const assert = require('assert');
const path = require('path');
const fs = require('fs-extra');
const { AuthlessClient, AuthlessLowLevelClient } = require('../../src');
const { AuthlessRouter } = require('@authless/router');
const {
  AuthlessServiceLinkedin,
  AuthlessServiceLinkedinPerson
} = require('@authless/service-linkedin');

const urls = {
  company: 'https://www.linkedin.com/company/meero/',
  person: 'https://linkedin.com/in/ACwAAAOaPvgBv_fE-F3vKEmWAWsMHCCwegV8GTw'
}

describe('AuthlessClient', () => {
  let authlessClient, authlessLowLevelClient, authlessLinkedin, authlessLinkedinPerson;
  before(() => {
    authlessLowLevelClient = new AuthlessLowLevelClient({
      uri: 'http://example.com:4000',
      retries: 1,
      cache: {
        existsFn: async (url) => fs.exists(path.join(
          __dirname, './data/', `${encodeURIComponent(url)}.json`)),
        retrieveFn: async (url) => fs.readJson(path.join(
          __dirname, './data', `${encodeURIComponent(url)}.json`))
      }
    });
    authlessLinkedin = new AuthlessServiceLinkedin();
    authlessLinkedinPerson = new AuthlessServiceLinkedinPerson();
    authlessClient = new AuthlessClient({
      lowLevelClient: authlessLowLevelClient,
      retries: 1,
      router: new AuthlessRouter([
        ...authlessLinkedin.getRoutes(),
        ...authlessLinkedinPerson.getRoutes(),
      ])
    });
  });

  it('returns resource', async () => {
    const response = await authlessClient.url({u: urls.person});
    console.log(response);
    console.log('done');
  });
});
