package j$.time.chrono;

import j$.time.Instant;
import j$.time.LocalDate;
import j$.time.ZoneId;
import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/* JADX INFO: loaded from: classes2.dex */
public final class u extends AbstractC2282a implements Serializable {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final u f19174d = new u();
    private static final long serialVersionUID = 459996390165777884L;

    @Override // j$.time.chrono.k
    public final String s() {
        return "Japanese";
    }

    @Override // j$.time.chrono.k
    public final String T() {
        return "japanese";
    }

    @Override // j$.time.chrono.k
    public final ChronoLocalDate G(int i6, int i7, int i8) {
        return new w(LocalDate.h0(i6, i7, i8));
    }

    @Override // j$.time.chrono.k
    public final ChronoLocalDate z(int i6, int i7) {
        return new w(LocalDate.k0(i6, i7));
    }

    @Override // j$.time.chrono.k
    public final ChronoLocalDate q(long j4) {
        return new w(LocalDate.j0(j4));
    }

    @Override // j$.time.chrono.k
    public final ChronoLocalDate M() {
        return new w(LocalDate.J(LocalDate.g0(j$.time.b.c())));
    }

    @Override // j$.time.chrono.k
    public final ChronoLocalDate t(j$.time.temporal.n nVar) {
        if (nVar instanceof w) {
            return (w) nVar;
        }
        return new w(LocalDate.J(nVar));
    }

    @Override // j$.time.chrono.k
    public final boolean D(long j4) {
        return r.f19171d.D(j4);
    }

    private u() {
    }

    @Override // j$.time.chrono.k
    public final int v(l lVar, int i6) {
        if (!(lVar instanceof x)) {
            throw new ClassCastException("Era must be JapaneseEra");
        }
        x xVar = (x) lVar;
        int iC0 = (xVar.s().c0() + i6) - 1;
        if (i6 != 1 && (iC0 < -999999999 || iC0 > 999999999 || iC0 < xVar.s().c0() || lVar != x.q(LocalDate.h0(iC0, 1, 1)))) {
            throw new j$.time.c("Invalid yearOfEra value");
        }
        return iC0;
    }

    @Override // j$.time.chrono.k
    public final l P(int i6) {
        return x.v(i6);
    }

    @Override // j$.time.chrono.k
    public final List C() {
        return j$.time.b.b(x.z());
    }

    @Override // j$.time.chrono.k
    public final j$.time.temporal.x W(j$.time.temporal.a aVar) {
        switch (t.f19173a[aVar.ordinal()]) {
            case 1:
            case 2:
            case 3:
            case 4:
                throw new j$.time.temporal.w("Unsupported field: " + aVar);
            case 5:
                return j$.time.temporal.x.k(1L, x.x(), 999999999 - x.r().s().c0());
            case 6:
                return j$.time.temporal.x.k(1L, x.w(), j$.time.temporal.a.DAY_OF_YEAR.B().d());
            case 7:
                return j$.time.temporal.x.j(w.f19176d.c0(), 999999999L);
            case 8:
                return j$.time.temporal.x.j(x.f19180d.p(), x.r().p());
            default:
                return aVar.B();
        }
    }

    @Override // j$.time.chrono.AbstractC2282a, j$.time.chrono.k
    public final ChronoLocalDate R(Map map, j$.time.format.G g6) {
        return (w) super.R(map, g6);
    }

    @Override // j$.time.chrono.AbstractC2282a
    final ChronoLocalDate Y(Map map, j$.time.format.G g6) {
        w wVarD0;
        j$.time.temporal.a aVar = j$.time.temporal.a.ERA;
        Long l = (Long) map.get(aVar);
        x xVarV = l != null ? x.v(W(aVar).a(l.longValue(), aVar)) : null;
        j$.time.temporal.a aVar2 = j$.time.temporal.a.YEAR_OF_ERA;
        Long l6 = (Long) map.get(aVar2);
        int iA = l6 != null ? W(aVar2).a(l6.longValue(), aVar2) : 0;
        if (xVarV == null && l6 != null && !map.containsKey(j$.time.temporal.a.YEAR) && g6 != j$.time.format.G.STRICT) {
            xVarV = x.z()[x.z().length - 1];
        }
        if (l6 != null && xVarV != null) {
            j$.time.temporal.a aVar3 = j$.time.temporal.a.MONTH_OF_YEAR;
            if (map.containsKey(aVar3)) {
                j$.time.temporal.a aVar4 = j$.time.temporal.a.DAY_OF_MONTH;
                if (map.containsKey(aVar4)) {
                    map.remove(aVar);
                    map.remove(aVar2);
                    if (g6 == j$.time.format.G.LENIENT) {
                        return new w(LocalDate.h0((xVarV.s().c0() + iA) - 1, 1, 1)).Y(Math.subtractExact(((Long) map.remove(aVar3)).longValue(), 1L), j$.time.temporal.b.MONTHS).Y(Math.subtractExact(((Long) map.remove(aVar4)).longValue(), 1L), j$.time.temporal.b.DAYS);
                    }
                    int iA2 = W(aVar3).a(((Long) map.remove(aVar3)).longValue(), aVar3);
                    int iA3 = W(aVar4).a(((Long) map.remove(aVar4)).longValue(), aVar4);
                    if (g6 != j$.time.format.G.SMART) {
                        LocalDate localDate = w.f19176d;
                        LocalDate localDateH0 = LocalDate.h0((xVarV.s().c0() + iA) - 1, iA2, iA3);
                        if (localDateH0.d0(xVarV.s()) || xVarV != x.q(localDateH0)) {
                            throw new j$.time.c("year, month, and day not valid for Era");
                        }
                        return new w(xVarV, iA, localDateH0);
                    }
                    if (iA < 1) {
                        throw new j$.time.c("Invalid YearOfEra: " + iA);
                    }
                    int iC0 = (xVarV.s().c0() + iA) - 1;
                    try {
                        wVarD0 = new w(LocalDate.h0(iC0, iA2, iA3));
                    } catch (j$.time.c unused) {
                        wVarD0 = new w(LocalDate.h0(iC0, iA2, 1)).d0(new j$.time.temporal.q(0));
                    }
                    if (wVarD0.V() == xVarV || wVarD0.j(j$.time.temporal.a.YEAR_OF_ERA) <= 1 || iA <= 1) {
                        return wVarD0;
                    }
                    throw new j$.time.c("Invalid YearOfEra for Era: " + xVarV + " " + iA);
                }
            }
            j$.time.temporal.a aVar5 = j$.time.temporal.a.DAY_OF_YEAR;
            if (map.containsKey(aVar5)) {
                map.remove(aVar);
                map.remove(aVar2);
                if (g6 == j$.time.format.G.LENIENT) {
                    return new w(LocalDate.k0((xVarV.s().c0() + iA) - 1, 1)).Y(Math.subtractExact(((Long) map.remove(aVar5)).longValue(), 1L), j$.time.temporal.b.DAYS);
                }
                int iA4 = W(aVar5).a(((Long) map.remove(aVar5)).longValue(), aVar5);
                LocalDate localDate2 = w.f19176d;
                LocalDate localDateK0 = iA == 1 ? LocalDate.k0(xVarV.s().c0(), (xVarV.s().Y() + iA4) - 1) : LocalDate.k0((xVarV.s().c0() + iA) - 1, iA4);
                if (localDateK0.d0(xVarV.s()) || xVarV != x.q(localDateK0)) {
                    throw new j$.time.c("Invalid parameters");
                }
                return new w(xVarV, iA, localDateK0);
            }
        }
        return null;
    }

    @Override // j$.time.chrono.k
    public final ChronoZonedDateTime x(Instant instant, ZoneId zoneId) {
        return j.J(this, instant, zoneId);
    }

    private void readObject(ObjectInputStream objectInputStream) throws InvalidObjectException {
        throw new InvalidObjectException("Deserialization via serialization delegate");
    }

    Object writeReplace() {
        return new D((byte) 1, this);
    }
}
