You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: stats.rb
    path of file: ./repos/zammad/lib
    
    the code of the file until where you have to start completion: # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

class Stats

=begin

generate stats for user

  Stats.generate

returns

  result = true # if generation was successfu
    
  def self.generate

    # generate stats per agent
    users = User.with_permissions('ticket.agent')
    agent_count = 0
    user_result = {}
    users.each do |user|
      next if user.id == 1
      next if !user.active

      agent_count += 1
      data = {}

      backends = Setting.where(area: 'Dashboard::Stats')
      if backends.blank?
        raise __("No settings with area 'Dashboard::Stats' defined")
      end

      backends.each do |stats_item|
        # additional permission check
        next if stats_item.preferences[:permission] && !user.permissions?(stats_item.preferences[:permission])

        backend = stats_item.state_current[:value]
        if !backend
          raise "Dashboard::Stats backend #{stats_item.name} is not defined"
        end

        backend = backend.constantize

        data[backend] = backend.generate(user)
      end