package ca.canadapost.module.geofence;

import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import androidx.core.app.h;
import ca.canadapost.CanadaPostApp;
import ca.canadapost.core.data.db.cupboard.model.OutletGeofenceObject;
import com.canadapost.android.R;
import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofenceStatusCodes;
import com.google.android.gms.location.GeofencingEvent;
import java.util.ArrayList;
import java.util.List;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import tr.a;

@Metadata(d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\b\u0007\u0018\u0000 \f2\u00020\u0001:\u0001\rB\u0007¢\u0006\u0004\b\n\u0010\u000bJ\u0012\u0010\u0005\u001a\u00020\u00042\b\u0010\u0003\u001a\u0004\u0018\u00010\u0002H\u0002J\b\u0010\u0006\u001a\u00020\u0004H\u0002J\u0010\u0010\t\u001a\u00020\u00042\u0006\u0010\b\u001a\u00020\u0007H\u0014¨\u0006\u000e"}, d2 = {"Lca/canadapost/module/geofence/CPCGeofenceTransitionsJobIntentService;", "Landroidx/core/app/h;", "Lca/canadapost/core/data/db/cupboard/model/OutletGeofenceObject;", "outletGeofenceObject", "Lrm/n0;", "j", "k", "Landroid/content/Intent;", "intent", "g", "<init>", "()V", "y", "a", "app_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class CPCGeofenceTransitionsJobIntentService extends h {

    /* renamed from: y, reason: collision with root package name and from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);

    /* renamed from: ca.canadapost.module.geofence.CPCGeofenceTransitionsJobIntentService$a, reason: from kotlin metadata */
    /* loaded from: classes4.dex */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(k kVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final int c() {
            return R.drawable.statusbaricon_postmark;
        }

        public final void b(Context context, Intent work) {
            t.g(context, "context");
            t.g(work, "work");
            h.d(context, CPCGeofenceTransitionsJobIntentService.class, 1, work);
        }
    }

    private final void j(OutletGeofenceObject outletGeofenceObject) {
        if (outletGeofenceObject != null) {
            String string = getResources().getString(R.string.track_dnc_geofence_notification_msg_title);
            t.f(string, "getString(...)");
            Object systemService = getSystemService("notification");
            t.e(systemService, "null cannot be cast to non-null type android.app.NotificationManager");
            NotificationManager notificationManager = (NotificationManager) systemService;
            Intent intent = new Intent();
            intent.addFlags(603979776);
            intent.putExtra("INTENT_EXTRA_OUTLET_ID", outletGeofenceObject.getOutletId());
            Notification build = new Notification.Builder(this).setSmallIcon(INSTANCE.c()).setColor(getResources().getColor(R.color.cpc_red_40)).setContentTitle(getResources().getString(R.string.app_name)).setContentText(string).setContentIntent(PendingIntent.getActivity(this, 0, intent, 201326592)).setStyle(new Notification.BigTextStyle().bigText(string)).setAutoCancel(true).setChannelId("TestChannel").build();
            t.f(build, "build(...)");
            String string2 = getResources().getString(R.string.app_name);
            t.f(string2, "getString(...)");
            notificationManager.createNotificationChannel(new NotificationChannel("TestChannel", string2, 4));
            notificationManager.notify(998877665, build);
        }
    }

    private final void k() {
    }

    @Override // androidx.core.app.h
    protected void g(Intent intent) {
        t.g(intent, "intent");
        GeofencingEvent fromIntent = GeofencingEvent.fromIntent(intent);
        if (fromIntent == null) {
            return;
        }
        if (fromIntent.hasError()) {
            String statusCodeString = GeofenceStatusCodes.getStatusCodeString(fromIntent.getErrorCode());
            t.f(statusCodeString, "getStatusCodeString(...)");
            a.f36618a.c(statusCodeString, new Object[0]);
            return;
        }
        int geofenceTransition = fromIntent.getGeofenceTransition();
        List<Geofence> triggeringGeofences = fromIntent.getTriggeringGeofences();
        if (triggeringGeofences == null) {
            triggeringGeofences = new ArrayList<>();
        }
        a.C0867a c0867a = a.f36618a;
        c0867a.a("onHandleIntent " + fromIntent + " transition=" + geofenceTransition + " " + fromIntent.getTriggeringLocation() + " " + triggeringGeofences.size(), new Object[0]);
        if ((geofenceTransition == 2 || geofenceTransition == 4) && triggeringGeofences.size() > 0) {
            Geofence geofence = triggeringGeofences.get(0);
            Application application = getApplication();
            t.e(application, "null cannot be cast to non-null type ca.canadapost.CanadaPostApp");
            OutletGeofenceObject a10 = ((CanadaPostApp) application).p().a(geofence.getRequestId());
            if (geofenceTransition == 4) {
                j(a10);
            } else {
                k();
            }
            c0867a.a("onHandleIntent " + a10, new Object[0]);
        }
    }
}
