class Lutaml::Model::KeyValueMapping

def deep_dup

def deep_dup
  self.class.new.tap do |new_mapping|
    new_mapping.instance_variable_set(:@mappings, duplicate_mappings)
  end
end

def duplicate_mappings

def duplicate_mappings
  @mappings.map(&:deep_dup)
end

def initialize

def initialize
  @mappings = []
end

def map(

def map(
  name,
  to: nil,
  render_nil: false,
  with: {},
  delegate: nil,
  child_mappings: nil
)
  validate!(name, to, with)
  @mappings << KeyValueMappingRule.new(
    name,
    to: to,
    render_nil: render_nil,
    with: with,
    delegate: delegate,
    child_mappings: child_mappings,
  )
end

def validate!(key, to, with)

def validate!(key, to, with)
  if to.nil? && with.empty?
    msg = ":to or :with argument is required for mapping '#{key}'"
    raise IncorrectMappingArgumentsError.new(msg)
  end
  if !with.empty? && (with[:from].nil? || with[:to].nil?)
    msg = ":with argument for mapping '#{key}' requires :to and :from keys"
    raise IncorrectMappingArgumentsError.new(msg)
  end
end