# Path: commands/core.py
# class Command(Resolvable):
#     pass
# 
# class Resolvable(metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     def resolve(self, scope):
#         pass
# 
# class EntityRef(Resolvable, metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     def is_single_entity(self, scope):
#         pass
# 
#     @property
#     def ref(self):
#         from .nbt import EntityReference
#         return EntityReference(self)
# 
# class SimpleResolve(Resolvable):
# 
#     def __init__(self, *args):
#         self.args = args
# 
#     def resolve(self, scope):
#         return ' '.join(map(lambda el: el.resolve(scope) \
#                              if isinstance(el, Resolvable) \
#                              else el, self.args))
# 
# class WorldPos(Resolvable):
# 
#     def __init__(self, x, y, z, block_pos=False):
#         is_anchor = self._check_coord(x, True, not block_pos)
#         was_anchor = self._check_coord(y, is_anchor, not block_pos)
#         is_anchor = self._check_coord(z, was_anchor, not block_pos)
#         if was_anchor:
#             assert is_anchor
#         self.x, self.y, self.z = x, y, z
#         self.block_pos = block_pos
# 
#     def _check_coord(self, val, allow_anchor, allow_float):
#         if isinstance(val, AnchorRelCoord):
#             assert allow_anchor
#             return True
#         if type(val) == float:
#             assert allow_float
#             return False
#         if type(val) == int:
#             return False
#         if isinstance(val, WorldRelCoord):
#             return False
#         assert False, val
# 
#     @property
#     def ref(self):
#         from .nbt import BlockReference
#         return BlockReference(self)
# 
#     def resolve(self, scope):
#         return '%s %s %s' % (self.x, self.y, self.z)
# 
# Path: commands/nbt.py
# class NBTStorable(Resolvable):
#     pass
# 
# Path: commands/scoreboard.py
# class ScoreRef(Resolvable):
# 
#     def __init__(self, target, objective):
#         assert isinstance(target, EntityRef)
#         assert isinstance(objective, ObjectiveRef)
#         self.target = target
#         self.objective = objective
# 
#     def resolve(self, scope):
#         return '%s %s' % (self.target.resolve(scope),
#                           self.objective.resolve(scope))
# 
# Path: commands/selector.py
# class ScoreRange(Resolvable):
# 
#     def __init__(self, min=None, max=None):
#         assert min is not None or max is not None
#         self.min = min
#         self.max = max
# 
#     def resolve(self, scope):
#         range = ''
#         if self.min is not None:
#             range = '%d' % self.min
#         if self.max is not None and self.max != self.min:
#             range += '..%d' % self.max
#         elif self.max is None:
#             range += '..'
#         return range


from .core import Command, Resolvable, EntityRef, SimpleResolve, WorldPos
from .nbt import NBTStorable
from .scoreboard import ScoreRef
from .selector import ScoreRange

class Execute(Command):

    def __init__(self, chain):
        self.chain = SimpleResolve(*chain._components)

    def resolve(self, scope):
        return 'execute %s' % self.chain.resolve(scope)

def ensure_selector(sel_arg):

# Path: commands/core.py
# class Command(Resolvable):
#     pass
# 
# class Resolvable(metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     def resolve(self, scope):
#         pass
# 
# class EntityRef(Resolvable, metaclass=abc.ABCMeta):
# 
#     @abc.abstractmethod
#     def is_single_entity(self, scope):
#         pass
# 
#     @property
#     def ref(self):
#         from .nbt import EntityReference
#         return EntityReference(self)
# 
# class SimpleResolve(Resolvable):
# 
#     def __init__(self, *args):
#         self.args = args
# 
#     def resolve(self, scope):
#         return ' '.join(map(lambda el: el.resolve(scope) \
#                              if isinstance(el, Resolvable) \
#                              else el, self.args))
# 
# class WorldPos(Resolvable):
# 
#     def __init__(self, x, y, z, block_pos=False):
#         is_anchor = self._check_coord(x, True, not block_pos)
#         was_anchor = self._check_coord(y, is_anchor, not block_pos)
#         is_anchor = self._check_coord(z, was_anchor, not block_pos)
#         if was_anchor:
#             assert is_anchor
#         self.x, self.y, self.z = x, y, z
#         self.block_pos = block_pos
# 
#     def _check_coord(self, val, allow_anchor, allow_float):
#         if isinstance(val, AnchorRelCoord):
#             assert allow_anchor
#             return True
#         if type(val) == float:
#             assert allow_float
#             return False
#         if type(val) == int:
#             return False
#         if isinstance(val, WorldRelCoord):
#             return False
#         assert False, val
# 
#     @property
#     def ref(self):
#         from .nbt import BlockReference
#         return BlockReference(self)
# 
#     def resolve(self, scope):
#         return '%s %s %s' % (self.x, self.y, self.z)
# 
# Path: commands/nbt.py
# class NBTStorable(Resolvable):
#     pass
# 
# Path: commands/scoreboard.py
# class ScoreRef(Resolvable):
# 
#     def __init__(self, target, objective):
#         assert isinstance(target, EntityRef)
#         assert isinstance(objective, ObjectiveRef)
#         self.target = target
#         self.objective = objective
# 
#     def resolve(self, scope):
#         return '%s %s' % (self.target.resolve(scope),
#                           self.objective.resolve(scope))
# 
# Path: commands/selector.py
# class ScoreRange(Resolvable):
# 
#     def __init__(self, min=None, max=None):
#         assert min is not None or max is not None
#         self.min = min
#         self.max = max
# 
#     def resolve(self, scope):
#         range = ''
#         if self.min is not None:
#             range = '%d' % self.min
#         if self.max is not None and self.max != self.min:
#             range += '..%d' % self.max
#         elif self.max is None:
#             range += '..'
#         return range


# Path: commands/execute.py
from .core import Command, Resolvable, EntityRef, SimpleResolve, WorldPos
from .nbt import NBTStorable
from .scoreboard import ScoreRef
from .selector import ScoreRange


class Execute(Command):

    def __init__(self, chain):
        self.chain = SimpleResolve(*chain._components)

    def resolve(self, scope):
        return 'execute %s' % self.chain.resolve(scope)

def ensure_selector(sel_arg):

    assert isinstance(sel_arg, EntityRef), sel_arg