// Path: src/com/irccloud/android/data/IRCCloudDatabase.java
// @Database(entities = {RecentConversation.class, BackgroundTask.class, LogExport.class, Notification.class, Notification_LastSeenEID.class, Notification_ServerNick.class, Avatar.class}, version = IRCCloudDatabase.VERSION, exportSchema = false)
// public abstract class IRCCloudDatabase extends RoomDatabase {
//     public static final String NAME = "irccloud";
//     public static final int VERSION = 13;
// 
//     public abstract RecentConversationsList.RecentConversationsDao RecentConversationsDao();
//     public abstract BackgroundTaskWorker.BackgroundTasksDao BackgroundTasksDao();
//     public abstract LogExportsList.LogExportsDao LogExportsDao();
//     public abstract NotificationsList.NotificationsDao NotificationsDao();
//     public abstract AvatarsList.AvatarsDao AvatarsDao();
// 
//     private static IRCCloudDatabase sInstance;
//     public static IRCCloudDatabase getInstance() {
//         if (sInstance == null) {
//             synchronized (IRCCloudDatabase.class) {
//                 if (sInstance == null) {
//                     sInstance = Room.databaseBuilder(IRCCloudApplication.getInstance().getApplicationContext(), IRCCloudDatabase.class, NAME)
//                             .fallbackToDestructiveMigrationFrom(12)
//                             .fallbackToDestructiveMigration()
//                             .fallbackToDestructiveMigrationOnDowngrade()
//                             .allowMainThreadQueries()
//                             .build();
//                 }
//             }
//         }
//         return sInstance;
//     }
// }
// 
// Path: src/com/irccloud/android/data/model/BackgroundTask.java
// @Entity
// public class BackgroundTask {
//     @Ignore
//     public static final int TYPE_FCM_REGISTER = 1;
//     @Ignore
//     public static final int TYPE_FCM_UNREGISTER = 2;
// 
//     @PrimaryKey
//     @NonNull
//     private String tag;
// 
//     private int type;
// 
//     private String session;
// 
//     private String data;
// 
//     public String getTag() {
//         return tag;
//     }
// 
//     public void setTag(String tag) {
//         this.tag = tag;
//     }
// 
//     public int getType() {
//         return type;
//     }
// 
//     public void setType(int type) {
//         this.type = type;
//     }
// 
//     public String getSession() {
//         return session;
//     }
// 
//     public void setSession(String session) {
//         this.session = session;
//     }
// 
//     public String getData() {
//         return data;
//     }
// 
//     public void setData(String data) {
//         this.data = data;
//     }
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingWorkPolicy;
import androidx.work.ListenableWorker;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.messaging.FirebaseMessaging;
import com.irccloud.android.data.IRCCloudDatabase;
import com.irccloud.android.data.model.BackgroundTask;
import org.json.JSONObject;
import java.util.List;
/*
 * Copyright (c) 2015 IRCCloud, Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.irccloud.android;






public class BackgroundTaskWorker extends Worker {
    @Dao
    public interface BackgroundTasksDao {
        @Query("SELECT * FROM BackgroundTask")
        List<BackgroundTask> getBackgroundTasks();

        @Query("SELECT * FROM BackgroundTask WHERE type = :type")
        List<BackgroundTask> getBackgroundTasks(int type);

        @Query("SELECT * FROM BackgroundTask WHERE type = :type AND data = :data")
        List<BackgroundTask> getBackgroundTasks(int type, String data);

        @Query("SELECT * FROM BackgroundTask WHERE tag = :tag LIMIT 1")
        BackgroundTask getBackgroundTask(String tag);

        @Insert(onConflict = OnConflictStrategy.REPLACE)
        void insert(BackgroundTask backgroundTask);

        @Update
        void update(BackgroundTask backgroundTask);

        @Delete
        void delete(BackgroundTask backgroundTask);
    }

    public BackgroundTaskWorker(@NonNull Context appContext, @NonNull WorkerParameters params) {
        super(appContext, params);
    }

    public static void registerGCM(String token) {
// Path: src/com/irccloud/android/data/IRCCloudDatabase.java
// @Database(entities = {RecentConversation.class, BackgroundTask.class, LogExport.class, Notification.class, Notification_LastSeenEID.class, Notification_ServerNick.class, Avatar.class}, version = IRCCloudDatabase.VERSION, exportSchema = false)
// public abstract class IRCCloudDatabase extends RoomDatabase {
//     public static final String NAME = "irccloud";
//     public static final int VERSION = 13;
// 
//     public abstract RecentConversationsList.RecentConversationsDao RecentConversationsDao();
//     public abstract BackgroundTaskWorker.BackgroundTasksDao BackgroundTasksDao();
//     public abstract LogExportsList.LogExportsDao LogExportsDao();
//     public abstract NotificationsList.NotificationsDao NotificationsDao();
//     public abstract AvatarsList.AvatarsDao AvatarsDao();
// 
//     private static IRCCloudDatabase sInstance;
//     public static IRCCloudDatabase getInstance() {
//         if (sInstance == null) {
//             synchronized (IRCCloudDatabase.class) {
//                 if (sInstance == null) {
//                     sInstance = Room.databaseBuilder(IRCCloudApplication.getInstance().getApplicationContext(), IRCCloudDatabase.class, NAME)
//                             .fallbackToDestructiveMigrationFrom(12)
//                             .fallbackToDestructiveMigration()
//                             .fallbackToDestructiveMigrationOnDowngrade()
//                             .allowMainThreadQueries()
//                             .build();
//                 }
//             }
//         }
//         return sInstance;
//     }
// }
// 
// Path: src/com/irccloud/android/data/model/BackgroundTask.java
// @Entity
// public class BackgroundTask {
//     @Ignore
//     public static final int TYPE_FCM_REGISTER = 1;
//     @Ignore
//     public static final int TYPE_FCM_UNREGISTER = 2;
// 
//     @PrimaryKey
//     @NonNull
//     private String tag;
// 
//     private int type;
// 
//     private String session;
// 
//     private String data;
// 
//     public String getTag() {
//         return tag;
//     }
// 
//     public void setTag(String tag) {
//         this.tag = tag;
//     }
// 
//     public int getType() {
//         return type;
//     }
// 
//     public void setType(int type) {
//         this.type = type;
//     }
// 
//     public String getSession() {
//         return session;
//     }
// 
//     public void setSession(String session) {
//         this.session = session;
//     }
// 
//     public String getData() {
//         return data;
//     }
// 
//     public void setData(String data) {
//         this.data = data;
//     }
// }


// Path: src/com/irccloud/android/BackgroundTaskWorker.java
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Looper;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import androidx.work.Constraints;
import androidx.work.Data;
import androidx.work.ExistingWorkPolicy;
import androidx.work.ListenableWorker;
import androidx.work.NetworkType;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.messaging.FirebaseMessaging;
import com.irccloud.android.data.IRCCloudDatabase;
import com.irccloud.android.data.model.BackgroundTask;
import org.json.JSONObject;
import java.util.List;

/*
 * Copyright (c) 2015 IRCCloud, Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.irccloud.android;






public class BackgroundTaskWorker extends Worker {
    @Dao
    public interface BackgroundTasksDao {
        @Query("SELECT * FROM BackgroundTask")
        List<BackgroundTask> getBackgroundTasks();

        @Query("SELECT * FROM BackgroundTask WHERE type = :type")
        List<BackgroundTask> getBackgroundTasks(int type);

        @Query("SELECT * FROM BackgroundTask WHERE type = :type AND data = :data")
        List<BackgroundTask> getBackgroundTasks(int type, String data);

        @Query("SELECT * FROM BackgroundTask WHERE tag = :tag LIMIT 1")
        BackgroundTask getBackgroundTask(String tag);

        @Insert(onConflict = OnConflictStrategy.REPLACE)
        void insert(BackgroundTask backgroundTask);

        @Update
        void update(BackgroundTask backgroundTask);

        @Delete
        void delete(BackgroundTask backgroundTask);
    }

    public BackgroundTaskWorker(@NonNull Context appContext, @NonNull WorkerParameters params) {
        super(appContext, params);
    }

    public static void registerGCM(String token) {
        List<BackgroundTask> tasks = IRCCloudDatabase.getInstance().BackgroundTasksDao().getBackgroundTasks(BackgroundTask.TYPE_FCM_REGISTER);