const express = require('express');
const router = express.Router();

const tools = require('../tools/general');

const server_constants = require('../tools/server_constants');

const { authenticate } = require('../middleware/authenticate');

const { MyGroup } = require('../models/mygroup');
const { User } = require('../models/user');
const { Stat } = require('../models/stat');

const mongoose = require('mongoose').set('debug', false)

const _ = require('lodash');

const { ObjectId } = require('mongodb');

// const { ExtraList } = require('../models/extralist');

router.post('/load', async (req, res) => {
  const idapp = req.body.idapp;
  const username = req.body.username;

  try {
    let datastat = await Stat.getStats(idapp);

    if (datastat) {
      datastat.checkuser = await User.checkUser(idapp, username);
    }

    res.send({ datastat });

  } catch (e) {
    console.error('Error', e);
  }


  /*
    let datastat = {
      num_tot_lista: 80,
      num_reg: 40,
      lastsreg: [
        { username: 'prova3', name: 'Datti', surname: 'Una Mossa', nationality: 'gb', date_reg: new Date()},
        { username: 'prova2', name: 'Pinco', surname: 'Pallino', nationality: 'de', date_reg: new Date()},
        { username: 'paoloar77', name: 'Paolo', surname: 'Arena', nationality: 'it', date_reg: new Date()},
        { username: 'mariorossi', name: 'Mario', surname: 'Rossi', nationality: 'es', date_reg: new Date()},
        { username: 'prova4', name: 'Quanto', surname: 'Siamo Fighi', nationality: 'uk', date_reg: new Date()},
        { username: 'prova5', name: 'Secondo', surname: 'PPP', nationality: 'sl', date_reg: new Date()},
      ]
    };
  */

});

module.exports = router;
