package com.mogo.realtime.util;

import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.RequiresApi;

import java.util.Objects;

/**
 * 经纬度
 */
public class MogoLatLng implements Parcelable {

    public final double lat;
    public final double lon;

    public MogoLatLng(double lat, double lon) {
        this.lat = lat;
        this.lon = lon;
    }

    public double getLat() {
        return lat;
    }

    public double getLon() {
        return lon;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MogoLatLng latLng = (MogoLatLng) o;
        return Double.compare(latLng.lat, lat) == 0 &&
                Double.compare(latLng.lon, lon) == 0;
    }

    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    @Override
    public int hashCode() {
        return Objects.hash(lat, lon);
    }

    @Override
    public String toString() {
        return "MogoLatLng{" +
                "lat=" + lat +
                ", lon=" + lon +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeDouble(this.lat);
        dest.writeDouble(this.lon);
    }

    protected MogoLatLng(Parcel in) {
        this.lat = in.readDouble();
        this.lon = in.readDouble();
    }

    public static final Creator<MogoLatLng> CREATOR = new Creator<MogoLatLng>() {
        @Override
        public MogoLatLng createFromParcel(Parcel source) {
            return new MogoLatLng(source);
        }

        @Override
        public MogoLatLng[] newArray(int size) {
            return new MogoLatLng[size];
        }
    };
}
