'use strict';

/**
 * HttpBackend — stub. The shape that any future remote product/asset DB will
 * implement so the resolver can swap backends without touching consumers.
 *
 * Disabled by default. Set EVOLV_ASSET_REMOTE=1 to opt in; even then this
 * stub throws on use because the upstream API is not yet defined. See
 * `assetApiConfig.js` for the URL/auth scaffolding that will eventually
 * land here.
 */
class HttpBackend {
    constructor({ url, headers = {}, namespace } = {}) {
        this.url = url;
        this.headers = headers;
        this.namespace = namespace;
    }

    static get enabled() {
        return process.env.EVOLV_ASSET_REMOTE === '1';
    }

    loadAll() {
        if (!HttpBackend.enabled) {
            throw new Error(
                'HttpBackend disabled (set EVOLV_ASSET_REMOTE=1 to enable); ' +
                'no synchronous remote fetch is implemented yet.',
            );
        }
        throw new Error(
            'HttpBackend.loadAll(): remote asset backend not yet implemented. ' +
            'Use FileBackend or implement this method against the WBD product API.',
        );
    }

    async refresh() {
        return this.loadAll();
    }
}

module.exports = HttpBackend;
