class ReeMapper::FieldsFilter

def self.build(only:, except:)

def self.build(only:, except:)
  return empty_filter if only.nil? && except.nil?
  strategy = if !only.nil?
    OnlyStrategy.new(only, except)
  elsif !except.nil?
    ExceptStrategy.new(except)
  else
    NoneStrategy
  end
  nested_fields_filters = {}
  
  only = only&.select { _1.is_a? Hash }&.reduce(&:merge)
  except = except&.select { _1.is_a? Hash }&.reduce(&:merge)
  only&.each { nested_fields_filters[_1] = build(only: _2, except: except&.dig(_1)) }
  except&.each { nested_fields_filters[_1] ||= build(only: nil, except: _2) }
  new(strategy, nested_fields_filters)
end

def self.empty_filter

def self.empty_filter
  @empty_filter ||= new(NoneStrategy, {}).freeze
end

def allow?(field)

def allow?(field)
  strategy.allow?(field)
end

def filter_for(field)

def filter_for(field)
  nested_fields_filters.fetch(field, self.class.empty_filter)
end

def initialize(strategy, nested_fields_filters)

def initialize(strategy, nested_fields_filters)
  @strategy              = strategy
  @nested_fields_filters = nested_fields_filters
end