package leigh.astro.unit;

import org.jastronomy.jsofa.JSOFA;

import java.util.Objects;

public class DegreesMinutesSeconds {
    private final double degrees;
    private final double minutes;
    private final double seconds;

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

        JSOFA.jauA2af(9, xRads, idmsf);

        this.degrees = idmsf[0];
        minutes = idmsf[1];
        seconds = idmsf[2];
    }

    public DegreesMinutesSeconds(double degrees, double minutes, double seconds) {
        this.degrees = degrees;
        this.minutes = minutes;
        this.seconds = seconds;
    }

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

    public double getDegrees() {
        return degrees;
    }

    public double getMinutes() {
        return minutes;
    }

    public double getSeconds() {
        return seconds;
    }

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

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

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