import { getCurrentEnvironment } from './getCurrentEnvironment';

export function Environment(Builder) {

    return class Wrapped extends Builder {

        constructor(...args) {

            super(...args);

            this._environments = new Set();

        }

        inEnvironment(environment) {

            this._environments.add(environment);

            return this;

        }

        get inDev() { return this.inEnvironment('development'); }

        get inProd() { return this.inEnvironment('production'); }

        build(...args) {

            if (this._environments.size && !this._environments.has(getCurrentEnvironment())) {
                return;
            }

            return super.build(...args);

        }

    };

}
