package com.android.systemui.secureline;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class SecureLineExpiryReceiver extends BroadcastReceiver {

    private static final String CHANNEL_ID =
            "secureline_expiry";

    @Override
    public void onReceive(
            Context context,
            Intent intent
    ) {

        int daysLeft =
                intent.getIntExtra(
                        "days_left",
                        -1
                );

        if (daysLeft <= 0 || daysLeft > 7) {
            return;
        }

        NotificationManager nm =
                context.getSystemService(
                        NotificationManager.class
                );

        if (nm == null) {
            return;
        }

        NotificationChannel channel =
                new NotificationChannel(
                        CHANNEL_ID,
                        "LemenzoOS License",
                        NotificationManager.IMPORTANCE_HIGH
                );

        nm.createNotificationChannel(channel);

        Notification notification =
                new Notification.Builder(
                        context,
                        CHANNEL_ID
                )
                .setSmallIcon(
                        com.android.internal.R.drawable.stat_sys_warning
                )
                .setContentTitle(
                        "LemenzoOS License Expiring"
                )
                .setContentText(
                        "License expires in "
                                + daysLeft
                                + " day(s). Renew your license soon."
                )
                .setPriority(
                        Notification.PRIORITY_HIGH
                )
                .setCategory(
                        Notification.CATEGORY_SYSTEM
                )
                .setAutoCancel(true)
                .build();

        nm.notify(7001, notification);
    }
}
