/*
 * Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
 * Departamento de Informatica - Universidade Federal do Parana
 *
 * This file is part of blendb.
 *
 * blendb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * blendb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with blendb.  If not, see <http://www.gnu.org/licenses/>.
 */

import * as express from "express";
import { Engine } from "../core/engine";
import { Adapter} from "../core/adapter";
import { Log } from "../core/log";

/**
 * Extension of Express requests that suports the addition
 * of an engine and an adapter.
 * This extension is required because some Middlewares
 * add some objetcs, in this case metrics and dimensions,
 * to the Request object. To typescript compiler do not
 * return a error the extension must be made.
 */
export interface Request extends express.Request {
    /** A engine object. Represents the database in BlenDB perspective. */
    engine: Engine;
    /** A adapter object. Used to communicate with the database in use. */
    adapter: Adapter;
    /** A csvParser function. Used to parse json object into csv file. */
    csvParser: (json: any, format: string, cb: (err: Error, csv?: string));
    /** A log object. Used store logs into file. */
    log: Log;
}

/**
 * Extension Middleware function of ExpressJS Module.
 * Uses the custom Request object and is used to define
 * the middlewares of BlenDB API.
 */
export interface Middleware {
    (req: Request, res: express.Response, next: express.NextFunction): void;
}