require "active_support"
require "active_support/core_ext"
require "marcelo/version"

module Marcelo
  require_relative "./marcelo/document"
  require_relative "./marcelo/parser"
  require_relative "./marcelo/serializer"

  # Parses the given data into a hash
  #
  #   Marcelo.parse <<-mabxml
  #     <?xml version="1.0" encoding="UTF-8"?>
  #     <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
  #       <ListRecords>
  #         <record>
  #           <header>
  #             <identifier>aleph-publish:000012345</identifier>
  #           </header>
  #           <metadata>
  #             <record xmlns="http://www.ddb.de/professionell/mabxml/mabxml-1.xsd">
  #               <leader>00123vM0.01234567------h</leader>
  #               <controlfield tag="LDR">00123vM0.01234567------h</controlfield>
  #               <datafield tag="001" ind1="-" ind2="1">
  #                 <subfield code="a">HT000123456</subfield>
  #               </datafield>
  #             </record>
  #           </metadata>
  #         </record>
  #       </ListRecords>
  #     </OAI-PMH>
  #   mabxml
  #
  # The given `mab` has to be a string. Currently, only MabXML is recognised. Support for
  # plain mab/aleph sequential mab may be implemented in the future.
  #
  # Internally, MaHash can utilize different parser implementations. If available, `OxParser`
  # is used, else the default is to use `NokogiriParser`. There is also a `OgaParser` which has
  # to be selected explicitly, if you want to use it.
  #
  # You can specifiy which parser to use with the `parser` option.
  #
  #   MaHash.parse(mab, parser: MaHash::MabXml::OgaParser)
  #
  def self.parse(data, options = {})
    Parser.call(data, options)
  end

  def self.serialize(data, options = {})
    raise ArgumentError unless options[:format]
    Serializer.call(data, options)
  end
end
