package leigh.astro.astrometrics;

import java.time.Instant;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Objects;

/**
 * Class representing a terrestrial observing location.
 *
 * @author Alex Leigh
 */
public class Location {
    private final String name;
    private final double lng;
    private final double lat;
    private final String tz = "US/Arizona";

    public Location(String name, double lat, double lng) {
        this.name = name;
        this.lng = lng;
        this.lat = lat;
    }

    /**
     * Return the local time at this observing location for the given time.
     */
    public LocalTime getLocalTime(Instant t) {
        return LocalTime.from(t.atZone(ZoneId.of(tz)));
    }

    public double getLng() {
        return lng;
    }

    public String getName() {
        return name;
    }

    public double getLat() {
        return lat;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Location location = (Location) o;
        return Double.compare(location.lng, lng) == 0 &&
                Double.compare(location.lat, lat) == 0 &&
                Objects.equals(name, location.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, lng, lat);
    }

    @Override
    public String toString() {
        return "Location{" +
                "name='" + name + '\'' +
                ", lng=" + lng +
                ", lat=" + lat +
                '}';
    }

}
