package net.letime.lecjoa.db;

import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.db.SupportSQLiteOpenHelper;
import android.arch.persistence.db.SupportSQLiteOpenHelper.Callback;
import android.arch.persistence.db.SupportSQLiteOpenHelper.Configuration;
import android.arch.persistence.room.DatabaseConfiguration;
import android.arch.persistence.room.InvalidationTracker;
import android.arch.persistence.room.RoomOpenHelper;
import android.arch.persistence.room.RoomOpenHelper.Delegate;
import android.arch.persistence.room.util.TableInfo;
import android.arch.persistence.room.util.TableInfo.Column;
import android.arch.persistence.room.util.TableInfo.ForeignKey;
import android.arch.persistence.room.util.TableInfo.Index;
import java.lang.IllegalStateException;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;

@SuppressWarnings("unchecked")
public class AppDatabase_Impl extends AppDatabase {
  private volatile TootDao _tootDao;

  private volatile AccountDao _accountDao;

  private volatile InstanceDao _instanceDao;

  @Override
  protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration configuration) {
    final SupportSQLiteOpenHelper.Callback _openCallback = new RoomOpenHelper(configuration, new RoomOpenHelper.Delegate(7) {
      @Override
      public void createAllTables(SupportSQLiteDatabase _db) {
        _db.execSQL("CREATE TABLE IF NOT EXISTS `TootEntity` (`uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `text` TEXT, `urls` TEXT, `contentWarning` TEXT, `inReplyToId` TEXT, `inReplyToText` TEXT, `inReplyToUsername` TEXT, `visibility` INTEGER)");
        _db.execSQL("CREATE TABLE IF NOT EXISTS `AccountEntity` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `domain` TEXT NOT NULL, `accessToken` TEXT NOT NULL, `isActive` INTEGER NOT NULL, `accountId` TEXT NOT NULL, `username` TEXT NOT NULL, `displayName` TEXT NOT NULL, `profilePictureUrl` TEXT NOT NULL, `notificationsEnabled` INTEGER NOT NULL, `notificationsMentioned` INTEGER NOT NULL, `notificationsFollowed` INTEGER NOT NULL, `notificationsReblogged` INTEGER NOT NULL, `notificationsFavorited` INTEGER NOT NULL, `notificationSound` INTEGER NOT NULL, `notificationVibration` INTEGER NOT NULL, `notificationLight` INTEGER NOT NULL, `lastNotificationId` TEXT NOT NULL, `activeNotifications` TEXT NOT NULL)");
        _db.execSQL("CREATE UNIQUE INDEX `index_AccountEntity_domain_accountId` ON `AccountEntity` (`domain`, `accountId`)");
        _db.execSQL("CREATE TABLE IF NOT EXISTS `InstanceEntity` (`instance` TEXT NOT NULL, `emojiList` TEXT, `maximumTootCharacters` INTEGER, PRIMARY KEY(`instance`))");
        _db.execSQL("CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)");
        _db.execSQL("INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"270cafec36212522f4f156f0c255cce8\")");
      }

      @Override
      public void dropAllTables(SupportSQLiteDatabase _db) {
        _db.execSQL("DROP TABLE IF EXISTS `TootEntity`");
        _db.execSQL("DROP TABLE IF EXISTS `AccountEntity`");
        _db.execSQL("DROP TABLE IF EXISTS `InstanceEntity`");
      }

      @Override
      protected void onCreate(SupportSQLiteDatabase _db) {
        if (mCallbacks != null) {
          for (int _i = 0, _size = mCallbacks.size(); _i < _size; _i++) {
            mCallbacks.get(_i).onCreate(_db);
          }
        }
      }

      @Override
      public void onOpen(SupportSQLiteDatabase _db) {
        mDatabase = _db;
        internalInitInvalidationTracker(_db);
        if (mCallbacks != null) {
          for (int _i = 0, _size = mCallbacks.size(); _i < _size; _i++) {
            mCallbacks.get(_i).onOpen(_db);
          }
        }
      }

      @Override
      protected void validateMigration(SupportSQLiteDatabase _db) {
        final HashMap<String, TableInfo.Column> _columnsTootEntity = new HashMap<String, TableInfo.Column>(8);
        _columnsTootEntity.put("uid", new TableInfo.Column("uid", "INTEGER", true, 1));
        _columnsTootEntity.put("text", new TableInfo.Column("text", "TEXT", false, 0));
        _columnsTootEntity.put("urls", new TableInfo.Column("urls", "TEXT", false, 0));
        _columnsTootEntity.put("contentWarning", new TableInfo.Column("contentWarning", "TEXT", false, 0));
        _columnsTootEntity.put("inReplyToId", new TableInfo.Column("inReplyToId", "TEXT", false, 0));
        _columnsTootEntity.put("inReplyToText", new TableInfo.Column("inReplyToText", "TEXT", false, 0));
        _columnsTootEntity.put("inReplyToUsername", new TableInfo.Column("inReplyToUsername", "TEXT", false, 0));
        _columnsTootEntity.put("visibility", new TableInfo.Column("visibility", "INTEGER", false, 0));
        final HashSet<TableInfo.ForeignKey> _foreignKeysTootEntity = new HashSet<TableInfo.ForeignKey>(0);
        final HashSet<TableInfo.Index> _indicesTootEntity = new HashSet<TableInfo.Index>(0);
        final TableInfo _infoTootEntity = new TableInfo("TootEntity", _columnsTootEntity, _foreignKeysTootEntity, _indicesTootEntity);
        final TableInfo _existingTootEntity = TableInfo.read(_db, "TootEntity");
        if (! _infoTootEntity.equals(_existingTootEntity)) {
          throw new IllegalStateException("Migration didn't properly handle TootEntity(net.letime.lecjoa.db.TootEntity).\n"
                  + " Expected:\n" + _infoTootEntity + "\n"
                  + " Found:\n" + _existingTootEntity);
        }
        final HashMap<String, TableInfo.Column> _columnsAccountEntity = new HashMap<String, TableInfo.Column>(18);
        _columnsAccountEntity.put("id", new TableInfo.Column("id", "INTEGER", true, 1));
        _columnsAccountEntity.put("domain", new TableInfo.Column("domain", "TEXT", true, 0));
        _columnsAccountEntity.put("accessToken", new TableInfo.Column("accessToken", "TEXT", true, 0));
        _columnsAccountEntity.put("isActive", new TableInfo.Column("isActive", "INTEGER", true, 0));
        _columnsAccountEntity.put("accountId", new TableInfo.Column("accountId", "TEXT", true, 0));
        _columnsAccountEntity.put("username", new TableInfo.Column("username", "TEXT", true, 0));
        _columnsAccountEntity.put("displayName", new TableInfo.Column("displayName", "TEXT", true, 0));
        _columnsAccountEntity.put("profilePictureUrl", new TableInfo.Column("profilePictureUrl", "TEXT", true, 0));
        _columnsAccountEntity.put("notificationsEnabled", new TableInfo.Column("notificationsEnabled", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationsMentioned", new TableInfo.Column("notificationsMentioned", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationsFollowed", new TableInfo.Column("notificationsFollowed", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationsReblogged", new TableInfo.Column("notificationsReblogged", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationsFavorited", new TableInfo.Column("notificationsFavorited", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationSound", new TableInfo.Column("notificationSound", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationVibration", new TableInfo.Column("notificationVibration", "INTEGER", true, 0));
        _columnsAccountEntity.put("notificationLight", new TableInfo.Column("notificationLight", "INTEGER", true, 0));
        _columnsAccountEntity.put("lastNotificationId", new TableInfo.Column("lastNotificationId", "TEXT", true, 0));
        _columnsAccountEntity.put("activeNotifications", new TableInfo.Column("activeNotifications", "TEXT", true, 0));
        final HashSet<TableInfo.ForeignKey> _foreignKeysAccountEntity = new HashSet<TableInfo.ForeignKey>(0);
        final HashSet<TableInfo.Index> _indicesAccountEntity = new HashSet<TableInfo.Index>(1);
        _indicesAccountEntity.add(new TableInfo.Index("index_AccountEntity_domain_accountId", true, Arrays.asList("domain","accountId")));
        final TableInfo _infoAccountEntity = new TableInfo("AccountEntity", _columnsAccountEntity, _foreignKeysAccountEntity, _indicesAccountEntity);
        final TableInfo _existingAccountEntity = TableInfo.read(_db, "AccountEntity");
        if (! _infoAccountEntity.equals(_existingAccountEntity)) {
          throw new IllegalStateException("Migration didn't properly handle AccountEntity(net.letime.lecjoa.db.AccountEntity).\n"
                  + " Expected:\n" + _infoAccountEntity + "\n"
                  + " Found:\n" + _existingAccountEntity);
        }
        final HashMap<String, TableInfo.Column> _columnsInstanceEntity = new HashMap<String, TableInfo.Column>(3);
        _columnsInstanceEntity.put("instance", new TableInfo.Column("instance", "TEXT", true, 1));
        _columnsInstanceEntity.put("emojiList", new TableInfo.Column("emojiList", "TEXT", false, 0));
        _columnsInstanceEntity.put("maximumTootCharacters", new TableInfo.Column("maximumTootCharacters", "INTEGER", false, 0));
        final HashSet<TableInfo.ForeignKey> _foreignKeysInstanceEntity = new HashSet<TableInfo.ForeignKey>(0);
        final HashSet<TableInfo.Index> _indicesInstanceEntity = new HashSet<TableInfo.Index>(0);
        final TableInfo _infoInstanceEntity = new TableInfo("InstanceEntity", _columnsInstanceEntity, _foreignKeysInstanceEntity, _indicesInstanceEntity);
        final TableInfo _existingInstanceEntity = TableInfo.read(_db, "InstanceEntity");
        if (! _infoInstanceEntity.equals(_existingInstanceEntity)) {
          throw new IllegalStateException("Migration didn't properly handle InstanceEntity(net.letime.lecjoa.db.InstanceEntity).\n"
                  + " Expected:\n" + _infoInstanceEntity + "\n"
                  + " Found:\n" + _existingInstanceEntity);
        }
      }
    }, "270cafec36212522f4f156f0c255cce8", "047a9a9fdeeb637e23302bd1ea881c78");
    final SupportSQLiteOpenHelper.Configuration _sqliteConfig = SupportSQLiteOpenHelper.Configuration.builder(configuration.context)
        .name(configuration.name)
        .callback(_openCallback)
        .build();
    final SupportSQLiteOpenHelper _helper = configuration.sqliteOpenHelperFactory.create(_sqliteConfig);
    return _helper;
  }

  @Override
  protected InvalidationTracker createInvalidationTracker() {
    return new InvalidationTracker(this, "TootEntity","AccountEntity","InstanceEntity");
  }

  @Override
  public void clearAllTables() {
    super.assertNotMainThread();
    final SupportSQLiteDatabase _db = super.getOpenHelper().getWritableDatabase();
    try {
      super.beginTransaction();
      _db.execSQL("DELETE FROM `TootEntity`");
      _db.execSQL("DELETE FROM `AccountEntity`");
      _db.execSQL("DELETE FROM `InstanceEntity`");
      super.setTransactionSuccessful();
    } finally {
      super.endTransaction();
      _db.query("PRAGMA wal_checkpoint(FULL)").close();
      if (!_db.inTransaction()) {
        _db.execSQL("VACUUM");
      }
    }
  }

  @Override
  public TootDao tootDao() {
    if (_tootDao != null) {
      return _tootDao;
    } else {
      synchronized(this) {
        if(_tootDao == null) {
          _tootDao = new TootDao_Impl(this);
        }
        return _tootDao;
      }
    }
  }

  @Override
  public AccountDao accountDao() {
    if (_accountDao != null) {
      return _accountDao;
    } else {
      synchronized(this) {
        if(_accountDao == null) {
          _accountDao = new AccountDao_Impl(this);
        }
        return _accountDao;
      }
    }
  }

  @Override
  public InstanceDao instanceDao() {
    if (_instanceDao != null) {
      return _instanceDao;
    } else {
      synchronized(this) {
        if(_instanceDao == null) {
          _instanceDao = new InstanceDao_Impl(this);
        }
        return _instanceDao;
      }
    }
  }
}
