# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

from mixbox import entities, fields

import cybox
import cybox.bindings.cybox_common as common_binding


class LocationFactory(entities.EntityFactory):
    @classmethod
    def entity_class(cls, key):
        return cybox.lookup_extension(key, default=Location)


class Location(entities.Entity):
    _binding = common_binding
    _binding_class = common_binding.LocationType
    _namespace = 'http://cybox.mitre.org/common-2'
    _XSI_TYPE = None  # overridden by subclasses

    id_ = fields.IdrefField("id")
    idref = fields.IdrefField("idref")
    name = fields.TypedField("Name")

    def to_dict(self):
        d = super(Location, self).to_dict()

        if self._XSI_TYPE:
            d["xsi:type"] = self._XSI_TYPE

        return d

    @staticmethod
    def lookup_class(xsi_type):
        return cybox.lookup_extension(xsi_type, default=Location)

[((22, 10, 22, 33), 'mixbox.fields.IdrefField', 'fields.IdrefField', ({(22, 28, 22, 32): '"""id"""'}, {}), "('id')", False, 'from mixbox import entities, fields\n'), ((23, 12, 23, 38), 'mixbox.fields.IdrefField', 'fields.IdrefField', ({(23, 30, 23, 37): '"""idref"""'}, {}), "('idref')", False, 'from mixbox import entities, fields\n'), ((24, 11, 24, 36), 'mixbox.fields.TypedField', 'fields.TypedField', ({(24, 29, 24, 35): '"""Name"""'}, {}), "('Name')", False, 'from mixbox import entities, fields\n'), ((13, 15, 13, 60), 'cybox.lookup_extension', 'cybox.lookup_extension', (), '', False, 'import cybox\n'), ((36, 15, 36, 65), 'cybox.lookup_extension', 'cybox.lookup_extension', (), '', False, 'import cybox\n')]