// **********************************************************************
//
// Generated by the ORBacus IDL to Java Translator
//
// Copyright (c) 2000
// Object Oriented Concepts, Inc.
// Billerica, MA, USA
//
// All Rights Reserved
//
// **********************************************************************

// Version: 4.0.5

package edu.sc.seis.sod.model.common;

import edu.sc.seis.seisFile.fdsnws.quakeml.Origin;
import edu.sc.seis.seisFile.fdsnws.stationxml.Channel;
import edu.sc.seis.seisFile.fdsnws.stationxml.Station;

import java.util.Objects;

//
// IDL:iris.edu/Fissures/Location:1.0
//
/** A location on or in the earth. */

public class Location
{
    
    Location()
    {
    }
    
    public static Location of(Origin origin) {
    	return new Location(origin.getLatitude().getValue(),
             origin.getLongitude().getValue(),
             new QuantityImpl(0, UnitImpl.METER),
             new QuantityImpl(origin.getDepth().getValue(), UnitImpl.METER));
    }
    
    @Deprecated
    public Location(Origin origin) {
        this(origin.getLatitude().getValue(),
             origin.getLongitude().getValue(),
             new QuantityImpl(0, UnitImpl.METER),
             new QuantityImpl(origin.getDepth().getValue(), UnitImpl.METER));
    }

    public static Location of(Channel channel) {
        if( ! channel.getElevation().getUnit().equalsIgnoreCase("meter")) {
            throw new IllegalArgumentException("Units of elevation should be meter");
        }
        if( ! channel.getDepth().getUnit().equalsIgnoreCase("meter")) {
            throw new IllegalArgumentException("Units of depth should be meter");
        }
        return new Location(channel.getLatitude().getValue(),
             channel.getLongitude().getValue(),
             new QuantityImpl(channel.getElevation().getValue(), UnitImpl.METER),
             new QuantityImpl(channel.getDepth().getValue(), UnitImpl.METER));
    }

    public static Location of(Station sta) {
        return new Location(sta.getLatitude().getValue(),
             sta.getLongitude().getValue(),
             new QuantityImpl(sta.getElevation().getValue(), UnitImpl.METER),
             new QuantityImpl(0, UnitImpl.METER));
    }
    
    public
    Location(float latitude,
             float longitude,
             QuantityImpl elevation,
             QuantityImpl depth) {
        this(latitude, longitude, elevation, depth, LocationType.GEOGRAPHIC);
    }

    public
    Location(float latitude,
             float longitude,
             QuantityImpl elevation,
             QuantityImpl depth,
             LocationType type)
    {
        this.latitude = latitude;
        this.longitude = longitude;
        this.elevation = elevation;
        this.depth = depth;
        this.type = type;
    }

    public String toString() {
        return "("+latitude+", "+longitude+") "+depth;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Location)) return false;
        Location location = (Location) o;
        return Float.compare(latitude, location.latitude) == 0 && Float.compare(longitude, location.longitude) == 0 && Objects.equals(elevation, location.elevation) && Objects.equals(depth, location.depth) && Objects.equals(type, location.type);
    }

    @Override
    public int hashCode() {
        return Objects.hash(latitude, longitude, elevation, depth, type);
    }

    public float latitude;
    public float longitude;
    public QuantityImpl elevation;
    public QuantityImpl depth;
    public LocationType type;
    
    
}
