package com.google.firebase;

import J4.c;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.media3.common.PlaybackException;
import j$.time.Instant;
import java.util.Date;
import kotlin.jvm.internal.h;
import kotlin.jvm.internal.o;
import kotlin.jvm.internal.v;
import m3.AbstractC2478m;
import w4.k;

/* JADX INFO: loaded from: classes3.dex */
public final class Timestamp implements Comparable<Timestamp>, Parcelable {
    private final int nanoseconds;
    private final long seconds;
    public static final Companion Companion = new Companion(null);
    public static final Parcelable.Creator<Timestamp> CREATOR = new Parcelable.Creator<Timestamp>() { // from class: com.google.firebase.Timestamp$Companion$CREATOR$1
        /* JADX WARN: Can't rename method to resolve collision */
        @Override // android.os.Parcelable.Creator
        public Timestamp createFromParcel(Parcel source) {
            o.h(source, "source");
            return new Timestamp(source.readLong(), source.readInt());
        }

        /* JADX WARN: Can't rename method to resolve collision */
        @Override // android.os.Parcelable.Creator
        public Timestamp[] newArray(int i6) {
            return new Timestamp[i6];
        }
    };

    public static final class Companion {
        public /* synthetic */ Companion(h hVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final k toPreciseTime(Date date) {
            long j4 = 1000;
            long time = date.getTime() / j4;
            int time2 = (int) ((date.getTime() % j4) * ((long) PlaybackException.CUSTOM_ERROR_CODE_BASE));
            return time2 < 0 ? new k(Long.valueOf(time - 1), Integer.valueOf(time2 + 1000000000)) : new k(Long.valueOf(time), Integer.valueOf(time2));
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final void validateRange(long j4, int i6) {
            if (i6 < 0 || i6 >= 1000000000) {
                throw new IllegalArgumentException(Z0.o.l("Timestamp nanoseconds out of range: ", i6).toString());
            }
            if (-62135596800L > j4 || j4 >= 253402300800L) {
                throw new IllegalArgumentException(A0.a.m("Timestamp seconds out of range: ", j4).toString());
            }
        }

        public final Timestamp now() {
            return new Timestamp(new Date());
        }

        private Companion() {
        }
    }

    public Timestamp(long j4, int i6) {
        Companion.validateRange(j4, i6);
        this.seconds = j4;
        this.nanoseconds = i6;
    }

    public static final Timestamp now() {
        return Companion.now();
    }

    @Override // android.os.Parcelable
    public int describeContents() {
        return 0;
    }

    public boolean equals(Object obj) {
        if (obj != this) {
            return (obj instanceof Timestamp) && compareTo((Timestamp) obj) == 0;
        }
        return true;
    }

    public final int getNanoseconds() {
        return this.nanoseconds;
    }

    public final long getSeconds() {
        return this.seconds;
    }

    public int hashCode() {
        long j4 = this.seconds;
        return (((((int) j4) * 1369) + ((int) (j4 >> 32))) * 37) + this.nanoseconds;
    }

    public final Date toDate() {
        return new Date((this.seconds * ((long) 1000)) + ((long) (this.nanoseconds / PlaybackException.CUSTOM_ERROR_CODE_BASE)));
    }

    public final Instant toInstant() {
        Instant instantOfEpochSecond = Instant.ofEpochSecond(this.seconds, this.nanoseconds);
        o.g(instantOfEpochSecond, "ofEpochSecond(seconds, nanoseconds.toLong())");
        return instantOfEpochSecond;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder("Timestamp(seconds=");
        sb.append(this.seconds);
        sb.append(", nanoseconds=");
        return com.google.android.recaptcha.internal.a.m(sb, this.nanoseconds, ')');
    }

    @Override // android.os.Parcelable
    public void writeToParcel(Parcel dest, int i6) {
        o.h(dest, "dest");
        dest.writeLong(this.seconds);
        dest.writeInt(this.nanoseconds);
    }

    @Override // java.lang.Comparable
    public int compareTo(Timestamp other) {
        o.h(other, "other");
        c[] cVarArr = {new v() { // from class: com.google.firebase.Timestamp.compareTo.1
            @Override // kotlin.jvm.internal.v, Q4.k
            public Object get(Object obj) {
                return Long.valueOf(((Timestamp) obj).getSeconds());
            }
        }, new v() { // from class: com.google.firebase.Timestamp.compareTo.2
            @Override // kotlin.jvm.internal.v, Q4.k
            public Object get(Object obj) {
                return Integer.valueOf(((Timestamp) obj).getNanoseconds());
            }
        }};
        for (int i6 = 0; i6 < 2; i6++) {
            c cVar = cVarArr[i6];
            int iD = AbstractC2478m.d((Comparable) cVar.invoke(this), (Comparable) cVar.invoke(other));
            if (iD != 0) {
                return iD;
            }
        }
        return 0;
    }

    public Timestamp(Date date) {
        o.h(date, "date");
        Companion companion = Companion;
        k preciseTime = companion.toPreciseTime(date);
        long jLongValue = ((Number) preciseTime.f25469a).longValue();
        int iIntValue = ((Number) preciseTime.f25470b).intValue();
        companion.validateRange(jLongValue, iIntValue);
        this.seconds = jLongValue;
        this.nanoseconds = iIntValue;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public Timestamp(Instant time) {
        this(time.getEpochSecond(), time.getNano());
        o.h(time, "time");
    }
}
