from typing import Tuple

from domain.commands.command import Command
from domain.entities.vacuum import Vacuum
from domain.world import World


class VacuumMoveCommand(Command):
    def __init__(
        self, world: World, vacuum: Vacuum, move_vector: Tuple[int, int]
    ) -> None:
        super().__init__()
        self.world = world
        self.vacuum = vacuum
        self.dx = move_vector[0]
        self.dy = move_vector[1]

    def run(self):
        end_x = self.vacuum.x + self.dx
        end_y = self.vacuum.y + self.dy

        if (
            end_x > self.world.width - 1
            or end_y > self.world.height - 1
            or end_x < 0
            or end_y < 0
        ):
            return

        if self.world.is_obstacle_at(end_x, end_y):
            return

        self.vacuum.x = end_x
        self.vacuum.y = end_y