"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPluginContext = void 0;
const faker_1 = require("./db/faker");
const fauna_1 = require("./db/fauna");
let pluginModels;
if (process.env.DB_DRIVER === "DB_FAUNA") {
    pluginModels = fauna_1.models;
}
else {
    pluginModels = faker_1.models;
}
/**
 * Anything that this plugin offers to the server context is retrieved here
 */
function getPluginContext({ req, models }) {
    //Merge models
    models = Object.assign(Object.assign({}, models), pluginModels);
    const user = () => __awaiter(this, void 0, void 0, function* () { return (req.headers.authorization ? yield models.userByToken(req.headers.authorization) : null); });
    return { user, models };
}
exports.getPluginContext = getPluginContext;
