package com.mogo.cloud.location.third.core;

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

import java.util.Arrays;

public class Location implements Parcelable, ILocation {
    private int locType = 0;
    private int gpsAccuracyStatus = -1;
    private int satellites = 0;
    private int carStatus = 0;
    private double latitude = 0;
    private double longitude = 0;
    private double altitude = 0;
    private long time = 0;
    private float bearing = 0;
    private float accuracy = 0;
    private float speed = 0;
    private String cityName = "";
    private String adCode = "";
    private String cityCode = "";
    private String provider = "";

    public Location() {
    }

    protected Location(Parcel in) {
        readFromParcel(in);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(locType);
        dest.writeInt(gpsAccuracyStatus);
        dest.writeInt(satellites);
        dest.writeInt(carStatus);
        dest.writeDouble(latitude);
        dest.writeDouble(longitude);
        dest.writeDouble(altitude);
        dest.writeLong(time);
        dest.writeFloat(bearing);
        dest.writeFloat(accuracy);
        dest.writeFloat(speed);
        dest.writeString(cityName);
        dest.writeString(adCode);
        dest.writeString(cityCode);
        dest.writeString(provider);
    }

    public void readFromParcel(Parcel in){
        locType = in.readInt();
        gpsAccuracyStatus = in.readInt();
        satellites = in.readInt();
        carStatus = in.readInt();
        latitude = in.readDouble();
        longitude = in.readDouble();
        altitude = in.readDouble();
        time = in.readLong();
        bearing = in.readFloat();
        accuracy = in.readFloat();
        speed = in.readFloat();
        cityName = in.readString();
        adCode = in.readString();
        cityCode = in.readString();
        provider = in.readString();
    }

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

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

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

    public float getBearing() {
        return bearing;
    }

    public void setBearing(float bearing) {
        this.bearing = bearing;
    }

    public float getAccuracy() {
        return accuracy;
    }

    public void setAccuracy(float accuracy) {
        this.accuracy = accuracy;
    }

    public String getProvider() {
        return provider;
    }

    public void setProvider(String provider) {
        this.provider = provider;
    }

    public float getSpeed() {
        return speed;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public double getAltitude() {
        return altitude;
    }

    public void setAltitude(double altitude) {
        this.altitude = altitude;
    }

    public void setAdCode(String adcode) {
        this.adCode = adcode;
    }

    public String getAdCode() {
        return adCode;
    }

    public int getLocType() {
        return locType;
    }

    public void setLocType(int locType) {
        this.locType = locType;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public String getCityCode() {
        return cityCode;
    }

    public void setCityCode(String cityCode) {
        this.cityCode = cityCode;
    }

    public String getCityName() {
        return cityName;
    }

    public void setCityName(String cityName) {
        this.cityName = cityName;
    }

    public int getGpsAccuracyStatus() {
        return gpsAccuracyStatus;
    }

    public void setGpsAccuracyStatus(int gpsAccuracyStatus) {
        this.gpsAccuracyStatus = gpsAccuracyStatus;
    }

    public int getSatellites() {
        return satellites;
    }

    public void setSatellites(int satellites) {
        this.satellites = satellites;
    }

    public int getCarStatus() {
        return carStatus;
    }

    public void setCarStatus(int carStatus) {
        this.carStatus = carStatus;
    }

    @Override
    public String toString() {
        return "Location{" +
                "locType=" + locType +
                ", gpsAccuracyStatus=" + gpsAccuracyStatus +
                ", satellites=" + satellites +
                ", carStatus=" + carStatus +
                ", latitude=" + latitude +
                ", longitude=" + longitude +
                ", altitude=" + altitude +
                ", time=" + time +
                ", bearing=" + bearing +
                ", accuracy=" + accuracy +
                ", speed=" + speed +
                ", cityName='" + cityName + '\'' +
                ", adCode='" + adCode + '\'' +
                ", cityCode='" + cityCode + '\'' +
                ", provider='" + provider + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Location location = (Location) o;
        return locType == location.locType &&
                gpsAccuracyStatus == location.gpsAccuracyStatus &&
                satellites == location.satellites &&
                carStatus == location.carStatus &&
                Double.compare(location.latitude, latitude) == 0 &&
                Double.compare(location.longitude, longitude) == 0 &&
                Double.compare(location.altitude, altitude) == 0 &&
                time == location.time &&
                Float.compare(location.bearing, bearing) == 0 &&
                Float.compare(location.accuracy, accuracy) == 0 &&
                Float.compare(location.speed, speed) == 0 &&
                equals(cityName, location.cityName) &&
                equals(adCode, location.adCode) &&
                equals(cityCode, location.cityCode) &&
                equals(provider, location.provider);
    }

    @Override
    public int hashCode() {
        return hash(locType, gpsAccuracyStatus, satellites, carStatus, latitude, longitude, altitude, time, bearing, accuracy, speed, cityName, adCode, cityCode, provider);
    }

    private static int hash(Object... values) {
        return Arrays.hashCode(values);
    }

    private static boolean equals(Object a, Object b) {
        return (a == b) || (a != null && a.equals(b));
    }

}
