package cz.senslog.connector.fetch.fofr;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

public class ParcelInfo {

    public static class Address {
        private final String name;
        private final String country;
        private final String city;
        private final String street;
        private final String zip;
        private final double latitude;
        private final double longitude;

        public Address(String name, String country, String city, String street, String zip, double latitude, double longitude) {
            this.name = name;
            this.country = country;
            this.city = city;
            this.street = street;
            this.zip = zip;
            this.latitude = latitude;
            this.longitude = longitude;
        }

        public String getName() {
            return name;
        }

        public String getCountry() {
            return country;
        }

        public String getCity() {
            return city;
        }

        public String getStreet() {
            return street;
        }

        public String getZip() {
            return zip;
        }

        public double getLatitude() {
            return latitude;
        }

        public double getLongitude() {
            return longitude;
        }
    }

    public static class TrackingStatus {
        private final int id;
        private final String name;
        private final LocalDateTime timestamp;
        private final WarehouseInfo warehouseInfo;

        public TrackingStatus(int id, String name, LocalDateTime timestamp, WarehouseInfo warehouseInfo) {
            this.id = id;
            this.name = name;
            this.timestamp = timestamp;
            this.warehouseInfo = warehouseInfo;
        }

        public int getId() {
            return id;
        }

        public String getName() {
            return name;
        }

        public LocalDateTime getTimestamp() {
            return timestamp;
        }

        public WarehouseInfo getWarehouseInfo() {
            return warehouseInfo;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            TrackingStatus that = (TrackingStatus) o;
            return id == that.id && Objects.equals(timestamp, that.timestamp);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id, timestamp);
        }
    }

    private final long parcelId;
    private final WarehouseInfo warehouseOrigin;
    private final LocalDateTime exportDatetime;
    private final List<TrackingStatus> trackingStatuses;
    private final Address dispatcherAddress;
    private final Address recipientAddress;

    public ParcelInfo(long parcelId, WarehouseInfo warehouseOrigin, LocalDateTime exportDatetime, List<TrackingStatus> trackingStatuses, Address dispatcherAddress, Address recipientAddress) {
        this.parcelId = parcelId;
        this.warehouseOrigin = warehouseOrigin;
        this.exportDatetime = exportDatetime;
        this.trackingStatuses = trackingStatuses;
        this.dispatcherAddress = dispatcherAddress;
        this.recipientAddress = recipientAddress;
    }

    public long getParcelId() {
        return parcelId;
    }

    public WarehouseInfo getWarehouseOrigin() {
        return warehouseOrigin;
    }

    public LocalDateTime getExportDatetime() {
        return exportDatetime;
    }

    public List<TrackingStatus> getTrackingStatuses() {
        return trackingStatuses;
    }

    public Address getDispatcherAddress() {
        return dispatcherAddress;
    }

    public Address getRecipientAddress() {
        return recipientAddress;
    }

    public TrackingStatus lastTrackingStatus() {
        return trackingStatuses.get(trackingStatuses.size()-1);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ParcelInfo that = (ParcelInfo) o;
        return parcelId == that.parcelId && Objects.equals(exportDatetime, that.exportDatetime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(parcelId, exportDatetime);
    }
}
