class LambdaMicrowave {
  constructor() {
    if(typeof global['LambdaMicrowave.class'] !== 'undefined' && global['LambdaMicrowave.class'] !== null) {
      console.log('getting from global', global['LambdaMicrowave.class']);
      return global['LambdaMicrowave.class'];
    }
    this.warm;
    global['LambdaMicrowave.class'] = this;
    this.defrost = this.defrost.bind(this);
    this.getContainerStatus = this.getContainerStatus.bind(this);
  }

  getContainerStatus() {
    let status;
    if(this.warm) {
      status = 'Lambda Container: Already WARM';
    } else {
      this.warm = true;
      status = 'Lambda Container: Changing from COLD to WARM';
    }
    return status;
  }

  defrost(event, context, callback) {
    if (event.source === 'serverless-plugin-warmup') {
      callback(null, this.getContainerStatus());
      process.exit(0);
    }
  }
}

module.exports = new LambdaMicrowave();
