/*
 * Copyright (C) 2026  Tim Zimmermann <tim@aglais.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.aglais.zms.ui.util;

import org.junit.jupiter.api.Test;
import org.jxmapviewer.viewer.GeoPosition;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * Testcases for {@link GeoURLImporter}
 */
public class GeoURLImporterTest {

    @Test
    public void testGoogleMapsPlaces() {
        GeoPosition position = GeoURLImporter.importFrom("https://www.google.com/maps/place/100+Van+Ness/@37.7749,"
                + "-122.4194,901m/data=!3m1!1e3!4m12!1m5!3m4!2zMzfCsDQ2JzI5LjYiTiAxMjLCsDI1JzA5LjgiVw!8m2!3d37.7748889"
                + "!4d-122.4193889!3m5!1s0x8085809eb26cc2c7:0x59b301d3e5599f7!8m2!3d37.7766802!4d-122.4192217!16s%2Fm"
                + "%2F0283bvh?entry=ttu&g_ep=EgoyMDI2MDIwNC4wIKXMDSoASAFQAw%3D%3D");

        assertEquals(new GeoPosition(37.7766802, -122.4192217), position);
    }

    @Test
    public void testGoogleMapsPlacesRaw() {
        GeoPosition position = GeoURLImporter.importFrom("https://www.google.com/maps/place/37%C2%B046'29.6%22N+122%"
                + "C2%B025'09.8%22W/@37.7749,-122.4194,17z/data=!4m5!3m4!4b1!8m2!3d37.7749!4d-122.4194");

        assertEquals(new GeoPosition(37.7749, -122.4194), position);
    }

    @Test
    public void testGoogleMapsSearch() {
        GeoPosition position = GeoURLImporter.importFrom("https://www.google.com/maps/search/37.7749,+-122.4194");

        assertEquals(new GeoPosition(37.7749, -122.4194), position);
    }


    @Test
    public void testOSMSearch() {
        GeoPosition position = GeoURLImporter.importFrom("https://www.openstreetmap.org/search?lat=37.7749"
                + "&lon=-122.4194&zoom=7#map=13/37.78455/-122.39697");

        assertEquals(new GeoPosition(37.7749, -122.4194), position);
    }

    @Test
    public void testGeoURI() {
        GeoPosition position = GeoURLImporter.importFrom("geo:37.7749,-122.4194?z=17.0");

        assertEquals(new GeoPosition(37.7749, -122.4194), position);
    }

}
