import { Router, Request, Response } from "express";
import * as bodyparser from "body-parser";

import { authRoute } from "../security/token";

const classRouter = Router();
classRouter.use(bodyparser.json());
classRouter.use(authRoute);

classRouter.get("/:id/topTen", async (req: Request, res: Response) => {
    // TODO: Deprecate this?
    if (!req.params) {
        res.send({
            error: "400",
            data: {
                msg: "No class specified",
            },
        });
        return;
    }

    console.log("STUB(get): /class/:id/topTen");

    let users: any[] = [];
    let nr = 10;
    for (let i = 0; i < 10; i++)
        users = users.concat({
            username: `Test User ${i}`,
            score: 100 * i,
            level: Math.floor(Math.random() * Math.floor(10)),
            nr: nr--,
        });

    // TODO: Implement
    res.send({
        error: "0",
        data: {
            topTen: users,
        }
    });
});

export default classRouter;
