class ArrayOfItemsType < ActiveModel::Type::Value
  # The `cast` method is used to convert an incoming value into the desired type.
  def cast(value)
    return unless value.present?

    Array.wrap(value).map do |item_data|
      # Assuming item_data is a hash, this creates an instance of the Item class.
      # You can modify this part to match your object's initializer.
      item_data # Return the item as-is if it's already an object
    end
  end

  # This method is used when defining the type to convert it to a string for serialization.
  def serialize(value)
    value
  end
end

# ActiveModel::Type.register(:array_of_items, ArrayOfItemsType)