module Admin
  class DashboardController < Admin::BaseController
    def index
      @stats = DashboardStats.new.call
      @host = HostMetrics.new.sample!
      @active_sessions = StreamSession
        .where(status: DashboardStats::ACTIVE_STATUSES)
        .includes(match: :team)
        .order(started_at: :desc)
      @teams = Team.includes(:matches).order(:name).limit(8)
    end

    def metrics
      host = HostMetrics.new.sample!
      stats = DashboardStats.new.call
      render json: { host: host, stats: stats, at: Time.current.iso8601 }
    end
  end
end
