package com.amplifyframework.core.model.temporal;

import com.amplifyframework.core.model.temporal.Temporal;
import com.google.gson.e;
import com.google.gson.g;
import com.google.gson.h;
import com.google.gson.i;
import com.google.gson.m;
import com.google.gson.n;
import com.google.gson.o;
import com.google.gson.p;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

/* loaded from: classes4.dex */
public final class GsonTemporalAdapters {

    /* loaded from: classes4.dex */
    public static final class DateAdapter implements p, h {
        @Override // com.google.gson.h
        public Temporal.Date deserialize(i iVar, Type type, g gVar) {
            try {
                return new Temporal.Date(iVar.l());
            } catch (IllegalArgumentException e10) {
                throw new m("Failed to deserialize " + iVar.l() + " as a Temporal.Date due to " + e10);
            }
        }

        @Override // com.google.gson.p
        public i serialize(Temporal.Date date, Type type, o oVar) {
            return new n(date.format());
        }
    }

    /* loaded from: classes4.dex */
    public static final class DateTimeAdapter implements p, h {
        @Override // com.google.gson.h
        public Temporal.DateTime deserialize(i iVar, Type type, g gVar) throws m {
            try {
                return new Temporal.DateTime(iVar.l());
            } catch (IllegalArgumentException e10) {
                throw new m("Failed to deserialize " + iVar.l() + " as a Temporal.DateTime due to " + e10);
            }
        }

        @Override // com.google.gson.p
        public i serialize(Temporal.DateTime dateTime, Type type, o oVar) {
            return new n(dateTime.format());
        }
    }

    /* loaded from: classes4.dex */
    public static final class JavaDateAdapter implements p {
        @Override // com.google.gson.p
        public i serialize(Date date, Type type, o oVar) {
            return new n(new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(date));
        }
    }

    /* loaded from: classes4.dex */
    public static final class TimeAdapter implements p, h {
        @Override // com.google.gson.h
        public Temporal.Time deserialize(i iVar, Type type, g gVar) throws m {
            try {
                return new Temporal.Time(iVar.l());
            } catch (IllegalArgumentException e10) {
                throw new m("Failed to deserialize " + iVar.l() + " as a Temporal.Time due to " + e10);
            }
        }

        @Override // com.google.gson.p
        public i serialize(Temporal.Time time, Type type, o oVar) {
            return new n(time.format());
        }
    }

    /* loaded from: classes4.dex */
    public static final class TimestampAdapter implements p, h {
        @Override // com.google.gson.h
        public Temporal.Timestamp deserialize(i iVar, Type type, g gVar) throws m {
            return new Temporal.Timestamp(iVar.k(), TimeUnit.SECONDS);
        }

        @Override // com.google.gson.p
        public i serialize(Temporal.Timestamp timestamp, Type type, o oVar) {
            return new n(Long.valueOf(timestamp.getSecondsSinceEpoch()));
        }
    }

    private GsonTemporalAdapters() {
    }

    public static void register(e eVar) {
        Objects.requireNonNull(eVar);
        eVar.c(Temporal.Date.class, new DateAdapter());
        eVar.c(Temporal.DateTime.class, new DateTimeAdapter());
        eVar.c(Temporal.Timestamp.class, new TimestampAdapter());
        eVar.c(Temporal.Time.class, new TimeAdapter());
        eVar.c(Date.class, new JavaDateAdapter());
    }
}
