<?php
namespace Whater\Application\UseCase\Zones;
use Whater\Application\UseCase\AbstractCommandHandler;
use Whater\Application\UseCase\Zones\CommandRequest\GetNearestTownByLatLongCommand;
use Whater\Domain\Zones\Model\Town;
use Whater\Domain\Zones\Repository\TownRepositoryInterface;
/**
* Class GetNearestTownByLatLongHandler
* @package Whater\Application\UseCase\User
*/
class GetNearestTownByLatLongHandler extends AbstractCommandHandler
{
/**
* @var TownRepositoryInterface
*/
private $repositoryTown;
/**
* @param TownRepositoryInterface $repositoryTown
*/
public function __construct(TownRepositoryInterface $repositoryTown)
{
$this->repositoryTown = $repositoryTown;
}
/**
* @param GetNearestTownByLatLongCommand $getNearestTownByLatLongCommand
* @return null|Town
*/
public function handle(GetNearestTownByLatLongCommand $getNearestTownByLatLongCommand): ?Town
{
// search nearest town in 20 Kms
$town = $this->repositoryTown->findOneByNearestLatLong(
$getNearestTownByLatLongCommand->latitude(),
$getNearestTownByLatLongCommand->longitude(),
$getNearestTownByLatLongCommand->kilometers(),
$getNearestTownByLatLongCommand->searchName(),
$getNearestTownByLatLongCommand->countryCode()
);
return $town;
}
}