import * as plugins from './plugins.js';
import { CheckResult } from './classes.checkresult.js';

export class LicenseChecker {

  async excludeLicenseWithinPath(pathArg: string, licenseArrayArg: string[]) {
    const checkResult = new CheckResult();
    const pnpm = new plugins.smartpnpm.SmartPnpm(pathArg);
    const plainResultArray = await pnpm.getDependencyLicenseFlatArray();
    plainResultArray.forEach((licenseResult) => {
      if (licenseArrayArg.indexOf(licenseResult.license) === -1) {
        checkResult.addPassing(licenseResult);
      } else {
        checkResult.addFailing(licenseResult);
      }
    });
    return checkResult;
  }

  async includeLicencesWithinPath(pathArg: string, licenseArrayArg: string[]) {
    const checkResult = new CheckResult();
    const pnpm = new plugins.smartpnpm.SmartPnpm(pathArg);
    const plainResultArray = await pnpm.getDependencyLicenseFlatArray();
    plainResultArray.forEach((licenseResult) => {
      if (licenseArrayArg.indexOf(licenseResult.license) !== -1) {
        checkResult.addPassing(licenseResult);
      } else {
        checkResult.addFailing(licenseResult);
      }
    });
    return checkResult;
  }
}
