#!/usr/bin/env python

#
# Generated Tue Mar  5 18:27:40 2024 by generateDS.py version 2.43.3.
# Python 3.11.3 (main, Apr 19 2023, 18:49:55) [Clang 14.0.6 ]
#
# Command line options:
#   ('-f', '')
#   ('-o', 'schema/order_lib.py')
#   ('-s', 'schema/order.py')
#
# Command line arguments:
#   definitions/salesorder.xsd
#
# Command line:
#   /Users/daniilossinkin/anaconda3/bin/generateDS -f -o "schema/order_lib.py" -s "schema/order.py" definitions/salesorder.xsd
#
# Current working directory (os.getcwd()):
#   exports
#

import os
import sys
from lxml import etree as etree_

import src.data.exports.schema.order_lib as supermod

def parsexml_(infile, parser=None, **kwargs):
    if parser is None:
        # Use the lxml ElementTree compatible parser so that, e.g.,
        #   we ignore comments.
        parser = etree_.ETCompatXMLParser()
    try:
        if isinstance(infile, os.PathLike):
            infile = os.path.join(infile)
    except AttributeError:
        pass
    doc = etree_.parse(infile, parser=parser, **kwargs)
    return doc

def parsexmlstring_(instring, parser=None, **kwargs):
    if parser is None:
        # Use the lxml ElementTree compatible parser so that, e.g.,
        #   we ignore comments.
        try:
            parser = etree_.ETCompatXMLParser()
        except AttributeError:
            # fallback to xml.etree
            parser = etree_.XMLParser()
    element = etree_.fromstring(instring, parser=parser, **kwargs)
    return element

#
# Globals
#

ExternalEncoding = ''
SaveElementTreeNode = True

#
# Data representation classes
#


class semiramisSub(supermod.semiramis):
    def __init__(self, created=None, locale=None, nlsMode='SINGLE_LANGUAGE', dateTimeMode='NORMALIZED', SalesOrder=None, **kwargs_):
        super(semiramisSub, self).__init__(created, locale, nlsMode, dateTimeMode, SalesOrder,  **kwargs_)
supermod.semiramis.subclass = semiramisSub
# end class semiramisSub


class SalesOrderTypeSub(supermod.SalesOrderType):
    def __init__(self, mark=None, mode=None, invalid=None, customerOrderData=None, customerData=None, invoicingPartyData=None, Type=None, Details=None, **kwargs_):
        super(SalesOrderTypeSub, self).__init__(mark, mode, invalid, customerOrderData, customerData, invoicingPartyData, Type, Details,  **kwargs_)
supermod.SalesOrderType.subclass = SalesOrderTypeSub
# end class SalesOrderTypeSub


class customerOrderDataTypeSub(supermod.customerOrderDataType):
    def __init__(self, mark=None, mode=None, invalid=None, purchaseOrder=None, **kwargs_):
        super(customerOrderDataTypeSub, self).__init__(mark, mode, invalid, purchaseOrder,  **kwargs_)
supermod.customerOrderDataType.subclass = customerOrderDataTypeSub
# end class customerOrderDataTypeSub


class customerDataTypeSub(supermod.customerDataType):
    def __init__(self, mark=None, mode=None, invalid=None, CustomerPartner=None, **kwargs_):
        super(customerDataTypeSub, self).__init__(mark, mode, invalid, CustomerPartner,  **kwargs_)
supermod.customerDataType.subclass = customerDataTypeSub
# end class customerDataTypeSub


class CustomerPartnerTypeSub(supermod.CustomerPartnerType):
    def __init__(self, mark=None, mode=None, invalid=None, number=None, **kwargs_):
        super(CustomerPartnerTypeSub, self).__init__(mark, mode, invalid, number,  **kwargs_)
supermod.CustomerPartnerType.subclass = CustomerPartnerTypeSub
# end class CustomerPartnerTypeSub


class invoicingPartyDataTypeSub(supermod.invoicingPartyDataType):
    def __init__(self, mark=None, mode=None, invalid=None, Partner=None, **kwargs_):
        super(invoicingPartyDataTypeSub, self).__init__(mark, mode, invalid, Partner,  **kwargs_)
supermod.invoicingPartyDataType.subclass = invoicingPartyDataTypeSub
# end class invoicingPartyDataTypeSub


class PartnerTypeSub(supermod.PartnerType):
    def __init__(self, mark=None, mode=None, invalid=None, number=None, **kwargs_):
        super(PartnerTypeSub, self).__init__(mark, mode, invalid, number,  **kwargs_)
supermod.PartnerType.subclass = PartnerTypeSub
# end class PartnerTypeSub


class TypeTypeSub(supermod.TypeType):
    def __init__(self, mark=None, mode=None, invalid=None, code=None, **kwargs_):
        super(TypeTypeSub, self).__init__(mark, mode, invalid, code,  **kwargs_)
supermod.TypeType.subclass = TypeTypeSub
# end class TypeTypeSub


class DetailsTypeSub(supermod.DetailsType):
    def __init__(self, mark=None, mode=None, invalid=None, totalQuantity=None, priceOriginType=None, grossPrice=None, imp_deliveryDate=None, imp_recommendedGrossPrice=None, imp_customerItemNumber=None, Item=None, **kwargs_):
        super(DetailsTypeSub, self).__init__(mark, mode, invalid, totalQuantity, priceOriginType, grossPrice, imp_deliveryDate, imp_recommendedGrossPrice, imp_customerItemNumber, Item,  **kwargs_)
supermod.DetailsType.subclass = DetailsTypeSub
# end class DetailsTypeSub


class totalQuantityTypeSub(supermod.totalQuantityType):
    def __init__(self, mark=None, mode=None, invalid=None, amount=None, Uom=None, **kwargs_):
        super(totalQuantityTypeSub, self).__init__(mark, mode, invalid, amount, Uom,  **kwargs_)
supermod.totalQuantityType.subclass = totalQuantityTypeSub
# end class totalQuantityTypeSub


class UomTypeSub(supermod.UomType):
    def __init__(self, mark=None, mode=None, invalid=None, code=None, **kwargs_):
        super(UomTypeSub, self).__init__(mark, mode, invalid, code,  **kwargs_)
supermod.UomType.subclass = UomTypeSub
# end class UomTypeSub


class grossPriceTypeSub(supermod.grossPriceType):
    def __init__(self, mark=None, mode=None, invalid=None, amount=None, Currency=None, **kwargs_):
        super(grossPriceTypeSub, self).__init__(mark, mode, invalid, amount, Currency,  **kwargs_)
supermod.grossPriceType.subclass = grossPriceTypeSub
# end class grossPriceTypeSub


class CurrencyTypeSub(supermod.CurrencyType):
    def __init__(self, mark=None, mode=None, invalid=None, isoCode=None, **kwargs_):
        super(CurrencyTypeSub, self).__init__(mark, mode, invalid, isoCode,  **kwargs_)
supermod.CurrencyType.subclass = CurrencyTypeSub
# end class CurrencyTypeSub


class imp_deliveryDateTypeSub(supermod.imp_deliveryDateType):
    def __init__(self, mark=None, mode=None, invalid=None, dateFrom=None, dateUntil=None, **kwargs_):
        super(imp_deliveryDateTypeSub, self).__init__(mark, mode, invalid, dateFrom, dateUntil,  **kwargs_)
supermod.imp_deliveryDateType.subclass = imp_deliveryDateTypeSub
# end class imp_deliveryDateTypeSub


class dateFromTypeSub(supermod.dateFromType):
    def __init__(self, mark=None, mode=None, invalid=None, specialValue=None, date=None, timeZone=None, **kwargs_):
        super(dateFromTypeSub, self).__init__(mark, mode, invalid, specialValue, date, timeZone,  **kwargs_)
supermod.dateFromType.subclass = dateFromTypeSub
# end class dateFromTypeSub


class dateUntilTypeSub(supermod.dateUntilType):
    def __init__(self, mark=None, mode=None, invalid=None, specialValue=None, date=None, timeZone=None, **kwargs_):
        super(dateUntilTypeSub, self).__init__(mark, mode, invalid, specialValue, date, timeZone,  **kwargs_)
supermod.dateUntilType.subclass = dateUntilTypeSub
# end class dateUntilTypeSub


class imp_recommendedGrossPriceTypeSub(supermod.imp_recommendedGrossPriceType):
    def __init__(self, mark=None, mode=None, invalid=None, amount=None, Currency=None, **kwargs_):
        super(imp_recommendedGrossPriceTypeSub, self).__init__(mark, mode, invalid, amount, Currency,  **kwargs_)
supermod.imp_recommendedGrossPriceType.subclass = imp_recommendedGrossPriceTypeSub
# end class imp_recommendedGrossPriceTypeSub


class CurrencyType1Sub(supermod.CurrencyType1):
    def __init__(self, mark=None, mode=None, invalid=None, isoCode=None, **kwargs_):
        super(CurrencyType1Sub, self).__init__(mark, mode, invalid, isoCode,  **kwargs_)
supermod.CurrencyType1.subclass = CurrencyType1Sub
# end class CurrencyType1Sub


class ItemTypeSub(supermod.ItemType):
    def __init__(self, mark=None, mode=None, invalid=None, materialType=None, Imp_Color=None, Imp_Size=None, ReferenceItem=None, **kwargs_):
        super(ItemTypeSub, self).__init__(mark, mode, invalid, materialType, Imp_Color, Imp_Size, ReferenceItem,  **kwargs_)
supermod.ItemType.subclass = ItemTypeSub
# end class ItemTypeSub


class Imp_ColorTypeSub(supermod.Imp_ColorType):
    def __init__(self, mark=None, mode=None, invalid=None, code=None, collectionFlag=None, **kwargs_):
        super(Imp_ColorTypeSub, self).__init__(mark, mode, invalid, code, collectionFlag,  **kwargs_)
supermod.Imp_ColorType.subclass = Imp_ColorTypeSub
# end class Imp_ColorTypeSub


class Imp_SizeTypeSub(supermod.Imp_SizeType):
    def __init__(self, mark=None, mode=None, invalid=None, code=None, SizeRegister=None, **kwargs_):
        super(Imp_SizeTypeSub, self).__init__(mark, mode, invalid, code, SizeRegister,  **kwargs_)
supermod.Imp_SizeType.subclass = Imp_SizeTypeSub
# end class Imp_SizeTypeSub


class SizeRegisterTypeSub(supermod.SizeRegisterType):
    def __init__(self, mark=None, mode=None, invalid=None, code=None, **kwargs_):
        super(SizeRegisterTypeSub, self).__init__(mark, mode, invalid, code,  **kwargs_)
supermod.SizeRegisterType.subclass = SizeRegisterTypeSub
# end class SizeRegisterTypeSub


class ReferenceItemTypeSub(supermod.ReferenceItemType):
    def __init__(self, mark=None, mode=None, invalid=None, number=None, **kwargs_):
        super(ReferenceItemTypeSub, self).__init__(mark, mode, invalid, number,  **kwargs_)
supermod.ReferenceItemType.subclass = ReferenceItemTypeSub
# end class ReferenceItemTypeSub


def get_root_tag(node):
    tag = supermod.Tag_pattern_.match(node.tag).groups()[-1]
    rootClass = None
    rootClass = supermod.GDSClassesMapping.get(tag)
    if rootClass is None and hasattr(supermod, tag):
        rootClass = getattr(supermod, tag)
    return tag, rootClass


def parse(inFilename, silence=False):
    parser = None
    doc = parsexml_(inFilename, parser)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'semiramis'
        rootClass = supermod.semiramis
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    if not SaveElementTreeNode:
        doc = None
        rootNode = None
    if not silence:
        sys.stdout.write('<?xml version="1.0" ?>\n')
        rootObj.export(
            sys.stdout, 0, name_=rootTag,
            namespacedef_='',
            pretty_print=True)
    return rootObj


def parseEtree(inFilename, silence=False):
    parser = None
    doc = parsexml_(inFilename, parser)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'semiramis'
        rootClass = supermod.semiramis
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    mapping = {}
    rootElement = rootObj.to_etree(None, name_=rootTag, mapping_=mapping)
    reverse_mapping = rootObj.gds_reverse_node_mapping(mapping)
    # Enable Python to collect the space used by the DOM.
    if not SaveElementTreeNode:
        doc = None
        rootNode = None
    if not silence:
        content = etree_.tostring(
            rootElement, pretty_print=True,
            xml_declaration=True, encoding="utf-8")
        sys.stdout.write(content)
        sys.stdout.write('\n')
    return rootObj, rootElement, mapping, reverse_mapping


def parseString(inString, silence=False):
    if sys.version_info.major == 2:
        from StringIO import StringIO
    else:
        from io import BytesIO as StringIO
    parser = None
    rootNode= parsexmlstring_(inString, parser)
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'semiramis'
        rootClass = supermod.semiramis
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    if not SaveElementTreeNode:
        rootNode = None
    if not silence:
        sys.stdout.write('<?xml version="1.0" ?>\n')
        rootObj.export(
            sys.stdout, 0, name_=rootTag,
            namespacedef_='')
    return rootObj


def parseLiteral(inFilename, silence=False):
    parser = None
    doc = parsexml_(inFilename, parser)
    rootNode = doc.getroot()
    rootTag, rootClass = get_root_tag(rootNode)
    if rootClass is None:
        rootTag = 'semiramis'
        rootClass = supermod.semiramis
    rootObj = rootClass.factory()
    rootObj.build(rootNode)
    # Enable Python to collect the space used by the DOM.
    if not SaveElementTreeNode:
        doc = None
        rootNode = None
    if not silence:
        sys.stdout.write('#from ??? import *\n\n')
        sys.stdout.write('import ??? as model_\n\n')
        sys.stdout.write('rootObj = model_.rootClass(\n')
        rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
        sys.stdout.write(')\n')
    return rootObj


USAGE_TEXT = """
Usage: python ???.py <infilename>
"""


def usage():
    print(USAGE_TEXT)
    sys.exit(1)


def main():
    args = sys.argv[1:]
    if len(args) != 1:
        usage()
    infilename = args[0]
    parse(infilename)


if __name__ == '__main__':
    #import pdb; pdb.set_trace()
    main()
