class ViewModel::ActiveRecord::AssociationData

def initialize(association_name, direct_reflection, viewmodel_classes, shared, optional, through_to, through_order_attr)

def initialize(association_name, direct_reflection, viewmodel_classes, shared, optional, through_to, through_order_attr)
  @association_name   = association_name
  @direct_reflection  = direct_reflection
  @shared             = shared
  @optional           = optional
  @through_to         = through_to
  @through_order_attr = through_order_attr
  if viewmodel_classes
    @viewmodel_classes = Array.wrap(viewmodel_classes).map! do |v|
      case v
      when String, Symbol
        ViewModel::Registry.for_view_name(v.to_s)
      when Class
        v
      else
        raise ArgumentError.new("Invalid viewmodel class: #{v.inspect}")
      end
    end
  end
  if through?
    # Through associations must always be an owned direct association to a
    # shared indirect target. We expect the user to set shared: true to
    # express the ownership of the indirect target, but this direct
    # association to the intermediate is in fact owned. This ownership
    # property isn't directly used anywhere: the synthetic intermediate
    # viewmodel is only used in the deserialization update operations, which
    # directly understands the semantics of through associations.
    raise ArgumentError.new("Through associations must be to a shared target") unless @shared
    raise ArgumentError.new("Through associations must be `has_many`") unless direct_reflection.macro == :has_many
  end
end