package com.foxx.androidcast;

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

/** Parcelable network self-test snapshot shared over AIDL. */
public final class NetworkConditions implements Parcelable {
    public static final Creator<NetworkConditions> CREATOR = new Creator<NetworkConditions>() {
        @Override
        public NetworkConditions createFromParcel(Parcel in) {
            return new NetworkConditions(in);
        }

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

    public long collectedAtMs;
    public String fingerprint;
    public String reportText;
    public boolean refreshing;

    public NetworkConditions() {
        this.collectedAtMs = 0L;
        this.fingerprint = "";
        this.reportText = "";
        this.refreshing = false;
    }

    public NetworkConditions(long collectedAtMs, String fingerprint, String reportText, boolean refreshing) {
        this.collectedAtMs = collectedAtMs;
        this.fingerprint = fingerprint != null ? fingerprint : "";
        this.reportText = reportText != null ? reportText : "";
        this.refreshing = refreshing;
    }

    private NetworkConditions(Parcel in) {
        collectedAtMs = in.readLong();
        fingerprint = in.readString();
        reportText = in.readString();
        refreshing = in.readInt() != 0;
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(collectedAtMs);
        dest.writeString(fingerprint);
        dest.writeString(reportText);
        dest.writeInt(refreshing ? 1 : 0);
    }
}
