'use strict'

const Analytics = require('../models/Analytics')

const analyticsController = {
  async getDashboardData(req, res) {
    try {
      const tenantId = req.tenant?.id
      const revenueStats = await Analytics.getRevenueStats(null, tenantId)
      const salesByDay   = await Analytics.getSalesByDay(tenantId)
      const salesByHour  = await Analytics.getSalesByHour(tenantId)
      const salesByRaffle = await Analytics.getSalesByRaffle(tenantId)

      return res.json({ revenueStats, salesByDay, salesByHour, salesByRaffle })
    } catch (e) {
      console.error('Erro no Analytics Dashboard', e.message)
      return res.status(500).json({ error: 'Erro interno ao consultar relatórios' })
    }
  }
}

module.exports = analyticsController
