<?php

use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Flow\Tests\FunctionalTestCase;
use Newland\Toubiz\Api\ObjectAdapter\Concern\ArticleConstants;
use Newland\Toubiz\Sync\Neos\Domain\Model\Article;
use Newland\Toubiz\Sync\Neos\Domain\Model\Weather;
use Newland\Toubiz\Sync\Neos\Service\WeatherService;

class WeatherServiceTest extends FunctionalTestCase
{
    protected static $testablePersistenceEnabled = true;

    /** @var WeatherService */
    private $subject;

    /** @var Article */
    private $dummyArticle;

    public function setUp(): void
    {
        parent::setUp();
        $this->subject = new WeatherService();
        $this->dummyArticle = new Article();
    }

    public function testSearchingForNonCityArticle(): void
    {
        $this->expectException(InvalidArgumentException::class);
        $this->dummyArticle->setMainType(ArticleConstants::TYPE_TOUR);
        $this->subject->findByCityArticle($this->dummyArticle);
    }

    public function testFetchingAnExistingCityWithoutGeoLocation(): void
    {
        $this->dummyArticle->setMainType(ArticleConstants::TYPE_CITY);
        $this->dummyArticle->setName('Aach');
        $weather = $this->subject->findByCityArticle($this->dummyArticle);
        $this->assertNull($weather);
    }

    public function testFetchingAnExistingCityWithGeoLocation(): void
    {
        $this->dummyArticle->setMainType(ArticleConstants::TYPE_CITY);
        $this->dummyArticle->setName('Aach');
        $this->dummyArticle->setLatitude(47.843221);
        $this->dummyArticle->setLongitude(8.852687);
        $weather = $this->subject->findByCityArticle($this->dummyArticle);
        $this->assertInstanceOf(Weather::class, $weather);
    }
}
