'use strict';

// eslint-disable-next-line no-undef
const SERVERLESS_PATH = $SERVERLESS_PATH;

const Serverless = require(SERVERLESS_PATH);

class LocalServerless extends Serverless {
  constructor(config) {
    super(config);
    this.isLocalStub = true;
  }
  eventuallyFallbackToLocal() {
    this.isLocallyInstalled = true;
    return Promise.resolve();
  }
  // TODO: Can be removed with next major
  async run() {
    const cachedValue = this._isInvokedByGlobalInstallation;
    // Temporary patch as local fallback triggers re-resolution of CLI input
    // which originally is pre-generated by `runServerless`, therefore breaking test setup
    this._isInvokedByGlobalInstallation = false;
    const promise = super.run();
    this._isInvokedByGlobalInstallation = cachedValue;
    return promise;
  }
};

LocalServerless.SERVERLESS_PATH = SERVERLESS_PATH;

module.exports = LocalServerless;
