package edu.utexas.quietplaces;


import org.joda.time.DateTime;

/**
 * Data model object for a single QuietPlace as stored in the database.
 * The QuietPlaceMapMarker class is also important because it combines
 * this object plus the Google map marker and related functionality.
 */
public class QuietPlace {
    private long id;
    private String comment;
    private double latitude;
    private double longitude;
    private double radius;
    private DateTime datetime;
    private String category;

    @Override
    public String toString() {
/*
        return String.format(
                "QP Lat: %s Long: %s Rad: %s - Cat: %s - %s - %s",
                getLatitude(), getLongitude(), getRadius(), getCategory(),
                getDatetimeString(), getComment()
        );
*/
        return getHistoryEventFormatted();
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public DateTime getDatetime() {
        return datetime;
    }

    public void setDatetime(DateTime datetime) {
        this.datetime = datetime;
    }

    public String getDatetimeString() {
        return DateUtils.getISO8601Date(getDatetime());
    }

    public void setDatetimeString(String datetimeString) {
        DateTime dt = DateUtils.parseISO8601Date(datetimeString);
        setDatetime(dt);
    }


    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getRadiusFormatted() {
        double radius = getRadius();
        if (radius <= 1000) {
            return String.format("%.2f m", radius);
        } else {
            return String.format("%.2f km", (radius/1000));
        }
    }

    /**
     * Returns a formatted string with lat/long
     * @return string
     */
    public String getLocationFormatted() {
        double latitude = getLatitude();
        double longitude = getLongitude();
        String latStr, longStr;
        if (latitude > 0.0) {
            latStr = String.format("%.3f N", latitude);
        }
        else {
            latStr = String.format("%.3f S", Math.abs(latitude));
        }
        if (longitude < 0.0) {
            longStr = String.format("%.3f W", Math.abs(longitude));
        } else {
            longStr = String.format("%.3f E", longitude);
        }
        return latStr + ", " + longStr;
    }

    /**
     * Returns a suitable description of this quiet place
     * for the history event message when we add it to the DB.
     * @return a formatted string representation of the current status
     */
    public String getHistoryEventFormatted() {
        // is this good enough?
        return String.format(
                "%s: %s - %s %s",
                getId(), getComment(), getLocationFormatted(), getRadiusFormatted()
        );
    }

}

@@ -2648,18 +2648,16 @@
 itude %3E 
-0.
 0) %7B%0A   
@@ -2691,17 +2691,17 @@
 rmat(%22%25.
-3
+5
 f N%22, la
@@ -2772,17 +2772,17 @@
 rmat(%22%25.
-3
+5
 f S%22, Ma
@@ -2838,10 +2838,8 @@
 e %3C 
-0.
 0) %7B
@@ -2878,17 +2878,17 @@
 rmat(%22%25.
-3
+5
 f W%22, Ma
@@ -2967,9 +2967,9 @@
 (%22%25.
-3
+5
 f E%22

Increase precision in lat/lng label