# apps/web/core/views/serializers/system_serializer.rb

module Core
  module Views
    # Serializes system-level information for the frontend
    #
    # Responsible for transforming application version, runtime information,
    # and security-related values for frontend consumption.
    module SystemSerializer
      # Serializes system data from view variables
      #
      # @param view_vars [Hash] The view variables containing system information
      # @param i18n [Object] The internationalization instance
      # @return [Hash] Serialized system data including version and security values
      def self.serialize(view_vars, _i18n)
        output = output_template

        output['ot_version']      = OT::VERSION.to_s
        output['ot_version_long'] = OT::VERSION.inspect
        output['ruby_version']    = RUBY_VERSION.to_s

        output['shrimp'] = view_vars['shrimp']
        output['nonce']  = view_vars['nonce']
        output
      end

      class << self
        # Provides the base template for system serializer output
        #
        # @return [Hash] Template with all possible system output fields
        def output_template
          {
            'ot_version' => nil,
            'ot_version_long' => nil,
            'ruby_version' => nil,
            'shrimp' => nil,
            'nonce' => nil,
          }
        end
      end
      SerializerRegistry.register(self)
    end
  end
end
