package de.avatic.lcc.model.azuremaps.geocoding;

import de.avatic.lcc.model.db.nodes.Location;

import java.util.List;

public class GeocodingResult {

    private final Feature feature;

    public GeocodingResult(Feature feature) {
        this.feature = feature;
    }

    public Location getLocation() {
        if (feature.getGeometry() != null &&
                feature.getGeometry().getCoordinates() != null &&
                feature.getGeometry().getCoordinates().size() >= 2) {
            // Azure Maps returns [longitude, latitude]
            return new Location(
                    feature.getGeometry().getCoordinates().get(0),
                    feature.getGeometry().getCoordinates().get(1)
            );
        }
        return null;
    }

    public Address getAddress() {
        return feature.getProperties() != null ? feature.getProperties().getAddress() : null;
    }

    public String getConfidence() {
        return feature.getProperties() != null ? feature.getProperties().getConfidence() : null;
    }

    public List<String> getMatchCodes() {
        return feature.getProperties() != null ? feature.getProperties().getMatchCodes() : null;
    }

    public String getGeocodeLevel() {
        return feature.getProperties() != null &&
                feature.getProperties().getGeocodePoints() != null &&
                !feature.getProperties().getGeocodePoints().isEmpty()
                ? feature.getProperties().getGeocodePoints().getFirst().getCalculationMethod() : null;
    }

    public List<GeocodePoint> getGeocodePoints() {
        return feature.getProperties() != null ? feature.getProperties().getGeocodePoints() : null;
    }

    public Feature getRawFeature() {
        return feature;
    }
}