# frozen_string_literal: true

# This code is part of Karafka Pro, a commercial component not licensed under LGPL.
# See LICENSE for details.

module Karafka
  module Web
    module Pro
      module Ui
        module Routes
          # Manages the errors related routes
          class Errors < Base
            route do |r|
              r.on 'errors' do
                controller = build(Controllers::ErrorsController)

                r.get :partition_id, Integer do |partition_id, offset|
                  if params.current_offset == -1
                    controller.show(partition_id, offset)
                  else
                    r.redirect root_path('errors', partition_id, params.current_offset)
                  end
                end

                r.get :partition_id do |partition_id|
                  controller.partition(partition_id)
                end

                r.get do
                  controller.index
                end
              end
            end
          end
        end
      end
    end
  end
end
