package leigh.astro.unit;

import org.jastronomy.jsofa.JSOFA;

import java.util.Objects;

public class HoursMinutesSeconds {
    private final double hours;
    private final double minutes;
    private final double seconds;

    public HoursMinutesSeconds(double degrees) {
        double xRads = Math.toRadians(degrees);
        int[] idmsf = new int[4];

        JSOFA.jauA2tf(9, xRads, idmsf);

        hours = idmsf[0];
        minutes = idmsf[1];
        seconds = idmsf[2];
    }

    public HoursMinutesSeconds(double hours, double minutes, double seconds) {
        this.hours = hours;
        this.minutes = minutes;
        this.seconds = seconds;
    }

    public double getHours() {
        return hours;
    }

    public double getMinutes() {
        return minutes;
    }

    public double getSeconds() {
        return seconds;
    }

    public String asString() {
        return hours + ":" + minutes + ":" + seconds;
    }

    @Override
    public String toString() {
        return "HoursMinutesSeconds{" +
                "hours=" + hours +
                ", minutes=" + minutes +
                ", seconds=" + seconds +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HoursMinutesSeconds that = (HoursMinutesSeconds) o;
        return Double.compare(that.hours, hours) == 0 && Double.compare(that.minutes, minutes) == 0 && Double.compare(that.seconds, seconds) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(hours, minutes, seconds);
    }
}
