# Copyright (C) 2019-2022 HERE Global B.V. and its affiliate(s).
# All rights reserved.
#
# This software and other materials contain proprietary information
# controlled by HERE and are protected by applicable copyright legislation.
# Any use and utilization of this software and other materials and
# disclosure to any third parties is conditional upon having a separate
# agreement with HERE for the access, use, utilization or disclosure of this
# software. In the absence of such agreement, the use of the software is not
# allowed.

"""Tests for here.inspector.utils."""

import geojson
import geopandas as gpd
import pytest
from here.inspector.utils import bounds_gdf, bounds_obj
from shapely.geometry import shape

test_data = [
    (geojson.Point((10, 20)), 20, 10, 20, 10),
    (geojson.MultiPoint(coordinates=[(0, 0), (10, 10)]), 0, 0, 10, 10),
    (geojson.MultiPoint(coordinates=[(10, 10), (20, 20)]), 10, 10, 20, 20),
]


@pytest.mark.parametrize("geojson_obj,south,west,north,east", test_data)
def test_bounds_obj(geojson_obj, south, west, north, east):
    """Test bounds_obj function."""
    ((s, w), (n, e)) = bounds_obj(geojson_obj)
    assert (south, west, north, east) == (s, w, n, e)


def test_bounds_obj_empty():
    """Test bounds_obj function in case of empty coordinates."""
    empty_collection = geojson.FeatureCollection([])
    with pytest.raises(ValueError):
        bounds_obj(empty_collection)


@pytest.mark.parametrize("geojson_obj,south,west,north,east", test_data)
def test_bounds_gdf(geojson_obj, south, west, north, east):
    """Test bounds_gdf function."""
    gdf = gpd.GeoDataFrame(geometry=[shape(geojson_obj)])
    ((s, w), (n, e)) = bounds_gdf(gdf)
    assert (south, west, north, east) == (s, w, n, e)
