<?php

namespace App\Tests\Application\Utils;

use App\Tests\Application\OtWebTestCase;

class GpsCoordinateTest extends OtWebTestCase
{
    public function testGpsCoordinteResource(): void
    {
        $this->logger->info("\033[1;34mStarting test... GPS coordinate reverse lookup\033[0m");
        $this->loginAs($this->user);
        $this->get('/api/gps-coordinate-reverse/48.8566/2.3522');
        $this->logger->info("\033[1;34mRequest made to /api/gps-coordinate-reverse/48.8566/2.3522\033[0m");
        $this->assertResponseStatusCodeSame(200);
        $this->logger->info("\033[1;34mReceived status code 200\033[0m");
        $this->assertJsonContains([
            '@context' => '/api/contexts/GpsCoordinate',
            '@id' => '/api/gps-coordinate-reverse/48.8564263/2.3525275780116',
            '@type' => 'GpsCoordinate',
            'latitude' => 48.856426299999995,
            'longitude' => 2.3525275780116073,
            'streetAddress' => "Place de l'Hôtel de Ville",
            'streetAddressSecond' => null,
            'streetAddressThird' => null,
            'cp' => '75004',
            'city' => null,
            'country' => null,
        ]);
        $this->logger->info("\033[1;32mTest 'GPS coordinate reverse lookup' succeeded\033[0m");

        $this->logger->info("\033[1;34mStarting test... GPS coordinate searching\033[0m");
        $this->get('/api/gps-coordinate-searching');
        $this->logger->info("\033[1;34mRequest made to /api/gps-coordinate-searching\033[0m");
        $this->assertResponseStatusCodeSame(200);
        $this->logger->info("\033[1;34mReceived status code 200\033[0m");
        $this->assertJsonContains([
            '@context' => '/api/contexts/GpsCoordinate',
            '@id' => '/api/gps-coordinate-searching',
            '@type' => 'hydra:Collection',
            'hydra:totalItems' => 1,
            'hydra:member' => [
                [
                    '@id' => '/api/gps-coordinate-reverse/0/0',
                    '@type' => 'GpsCoordinate',
                    'latitude' => 0,
                    'longitude' => 0,
                    'streetAddress' => null,
                    'streetAddressSecond' => null,
                    'streetAddressThird' => null,
                    'cp' => null,
                    'city' => null,
                    'country' => null,
                ],
            ],
        ]);
        $this->logger->info("\033[1;32mTest 'GPS coordinate searching' succeeded\033[0m");

        $this->logger->info("\033[1;34mStarting test... GPS coordinate reverse lookup with invalid coordinates\033[0m");
        $this->loginAs($this->user);
        $this->get('/api/gps-coordinate-reverse/12345.6789/98765.4321');
        $this->logger->info("\033[1;34mRequest made to /api/gps-coordinate-reverse/12345.6789/98765.4321\033[0m");
        $this->assertResponseStatusCodeSame(404);
        $this->logger->info("\033[1;34mReceived status code 404\033[0m");
        $this->assertJsonContains([
            '@context' => '/api/contexts/Error',
            '@type' => 'hydra:Error',
            'hydra:title' => 'An error occurred',
            'hydra:description' => 'Failed to retrieve GPS coordinates: No address found for the given GPS coordinates.',
        ]);
        $this->logger->info("\033[1;32mTest 'GPS coordinate reverse lookup with invalid coordinates' succeeded\033[0m");
    }
}
