package com.alwaysallthetime.adnlibutils.model;

import com.alwaysallthetime.adnlib.data.Annotation;

import java.util.HashMap;

public class DisplayLocation {
    private String mName;
    private double mLatitude;
    private double mLongitude;

    public static DisplayLocation fromCheckinAnnotation(Annotation checkin) {
        HashMap<String, Object> value = checkin.getValue();
        String locationName = (String) value.get("name");
        return new DisplayLocation(locationName, (Double)value.get("latitude"), (Double)value.get("longitude"));
    }

    public static DisplayLocation fromOhaiLocation(Annotation ohaiLocation) {
        HashMap<String, Object> value = ohaiLocation.getValue();
        String name = (String) value.get("name");
        Double latitude = (Double) value.get("latitude");
        Double longitude = (Double) value.get("longitude");
        if(name == null) {
            if(latitude != null && longitude != null) {
                name = getLatLongString(latitude.toString(), longitude.toString());
            }
        }
        return new DisplayLocation(name, (Double)value.get("latitude"), (Double)value.get("longitude"));
    }

    public DisplayLocation(double latitude, double longitude) {
        mLatitude = latitude;
        mLongitude = longitude;
    }

    public DisplayLocation(String name, double latitude, double longitude) {
        this(latitude, longitude);
        mName = name;
    }

    public String getName() {
        return mName;
    }

    public double getLatitude() {
        return mLatitude;
    }

    public double getLongitude() {
        return mLongitude;
    }

    private static String getLatLongString(String latitude, String longitude) {
        return String.format("%s, %s", latitude, longitude);
    }
}

@@ -175,24 +175,55 @@
 ring mName;%0A
+    private String mFactualId;%0A
     private 
@@ -236,24 +236,24 @@
  mLatitude;%0A
-
     private 
@@ -468,38 +468,114 @@
 name%22);%0A        
-return
+String factualId = (String) value.get(%22factual_id%22);%0A        DisplayLocation loc =
  new DisplayLoca
@@ -588,24 +588,35 @@
 ocationName,
+ factualId,
  (Double)val
@@ -660,32 +660,52 @@
 (%22longitude%22));%0A
+        return loc;%0A
     %7D%0A%0A    publi
@@ -1141,41 +1141,19 @@
 tude
-.toString(), longitude.toString()
+, longitude
 );%0A 
@@ -1279,32 +1279,230 @@
 tude%22));%0A    %7D%0A%0A
+    public static DisplayLocation fromGeolocation(Geolocation geolocation) %7B%0A        return new DisplayLocation(geolocation.getName(), geolocation.getLatitude(), geolocation.getLongitude());%0A    %7D%0A%0A
     public Displ
@@ -1751,32 +1751,223 @@
  = name;%0A    %7D%0A%0A
+    public DisplayLocation(String name, String factualId, double latitude, double longitude) %7B%0A        this(latitude, longitude);%0A        mName = name;%0A        mFactualId = factualId;%0A    %7D%0A%0A
     public Strin
@@ -2141,24 +2141,93 @@
 ude;%0A    %7D%0A%0A
+    public String getFactualId() %7B%0A        return mFactualId;%0A    %7D%0A%0A
     private 
@@ -2257,22 +2257,22 @@
 gString(
-String
+double
  latitud
@@ -2274,22 +2274,22 @@
 titude, 
-String
+double
  longitu
@@ -2333,24 +2333,39 @@
 s, %25s%22, 
+String.valueOf(
 latitude
 , longit
@@ -2348,34 +2348,50 @@
 valueOf(latitude
+)
 , 
+String.valueOf(
 longitude);%0A    
@@ -2380,22 +2380,23 @@
 f(longitude)
+)
 ;%0A    %7D%0A%7D%0A

create DisplayLocation from Geolocation object