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 mongoose = require('mongoose').set('debug', false)

const { User } = require('../models/user');
// const { Nave } = require('../models/nave');
// const { ListaIngresso } = require('../models/listaingresso');

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;


  let datastat = {
    num_reg: await User.getUsersRegistered(idapp),
    num_reg_today: await User.getUsersRegisteredToday(idapp),
    online_today: await User.getUsersOnLineToday(idapp),
    // num_passeggeri: await 0,
    // num_imbarcati: 0,
    // email_non_verif: await User.getEmailNotVerified(idapp),
    num_teleg_attivo: await User.getUsersTelegramAttivo(idapp),
    num_autorizzati: await User.getUsersAutorizzati(idapp),
    num_autorizzare: await User.getUsersAutorizzare(idapp),
    num_teleg_pending: await User.getUsersTelegramPending(idapp),
    // num_qualificati: await User.getNumUsersQualified(idapp, 2),
    // num_requisiti: await User.getNumUsersQualified(idapp, 0),
    // num_modalita_pagamento: await User.getnumPaymentOk(idapp),
    // num_part_zoom: await User.getUsersZoom(idapp),
    // num_part_accepted: await User.getSaw_and_Accepted(idapp),
    arr_nations: await User.findAllDistinctNationality(idapp),
    numreg_untilday: await User.calcnumRegUntilDay(idapp),
    reg_daily: await User.calcRegDaily(idapp),
    // imbarcati_daily: 0,
    // imbarcati_weekly: 0,
    reg_weekly: await User.calcRegWeekly(idapp),
    lastsreg: await User.getLastUsers(idapp),
    lastsonline: await User.getLastOnlineUsers(idapp),
    lastssharedlink: await User.getLastSharedLink(idapp),
    diffusorilist: await User.getDiffusoriUsers(idapp),
    receiveRislist: await User.getReceiveRISUsers(idapp),
    // receiveRislist: await User.find({idapp}).limit(20),
    receiveRislistgroup: await MyGroup.getReceiveRISGroups(idapp),
    strettelist: await User.getBestStretteDiManoUsers(idapp),
    checkuser: await User.checkUser(idapp, username),
    // navi_partite: await Nave.getNaviPartite(idapp),
    // navi_in_partenza: await Nave.getNaviInPartenza(idapp),
  };



  // console.table(datastat.lastsreg);

  /*
    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()},
      ]
    };
  */

  res.send({ datastat });
});

module.exports = router;
