# frozen_string_literal: true

require_relative 'abstract_handler'

module Hypertube
  module Core
    module Handler
      class GetStaticFieldHandler < Hypertube::Core::Handler::AbstractHandler
        def initialize
          @required_parameters_count = 2
        end

        def process(command)
          get_static_field(command)
        end

        def get_static_field(command)
          validate(command, @required_parameters_count, self.class.name)

          type = command.payload[0]
          value = command.payload[1]
          begin
            response = type.class_variable_get(value)
          rescue StandardError
            response = type.const_get(value)
          end
          response
        end
      end
    end
  end
end
