import { NextFunction, Request, Response, Router } from "express";
import { BaseRoute } from "./route";
import * as redis from "redis";
import { RedisClient } from "redis";


/**
 * / route
 *
 * @class User
 */
export class IndexRoute extends BaseRoute {
  private client: RedisClient = redis.createClient();
  /**
   * Create the routes.
   *
   * @class IndexRoute
   * @method create
   * @static
   */
  public static create(router: Router) {
    //log
    console.log("[IndexRoute::create] Creating index route.");
    //var client: RedisClient = redis.createClient();
    //var imena: string[] = client.lrange('imena', 0, -1, (err));


    //add home page route
    router.get("/", (req: Request, res: Response, next: NextFunction) => {
      new IndexRoute().index(req, res, next);
    });
  }

  /**
   * Constructor
   *
   * @class IndexRoute
   * @constructor
   */
  constructor() {
    super();
  }

  /**
   * The home page route.
   *
   * @class IndexRoute
   * @method index
   * @param req {Request} The express Request object.
   * @param res {Response} The express Response object.
   * @next {NextFunction} Execute the next method.
   */
  public index(req: Request, res: Response, next: NextFunction) {
    //set custom title
    this.title = "Filter";

    //set options
    let options: Object = {
      "niz" : "<prazen niz>",
      "vsebujeIme": 0,
      "vsebujePriimek": 0,
      "vsebujeUlico": 0,
      "vsebujeObliko": 0,
      "vsebujeDavcno": 0,
      "vsebujeMaticno": 0,
      "vsebujePravilo": 0,
      "najdeniFiltri": []
    };

    //render template
    this.render(req, res, "index", options);
  }
}