package net.letime.lecjoa.db;

import android.arch.persistence.db.SupportSQLiteStatement;
import android.arch.persistence.room.EntityDeletionOrUpdateAdapter;
import android.arch.persistence.room.EntityInsertionAdapter;
import android.arch.persistence.room.RoomDatabase;
import android.arch.persistence.room.RoomSQLiteQuery;
import android.database.Cursor;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unchecked")
public class AccountDao_Impl implements AccountDao {
  private final RoomDatabase __db;

  private final EntityInsertionAdapter __insertionAdapterOfAccountEntity;

  private final EntityDeletionOrUpdateAdapter __deletionAdapterOfAccountEntity;

  public AccountDao_Impl(RoomDatabase __db) {
    this.__db = __db;
    this.__insertionAdapterOfAccountEntity = new EntityInsertionAdapter<AccountEntity>(__db) {
      @Override
      public String createQuery() {
        return "INSERT OR REPLACE INTO `AccountEntity`(`id`,`domain`,`accessToken`,`isActive`,`accountId`,`username`,`displayName`,`profilePictureUrl`,`notificationsEnabled`,`notificationsMentioned`,`notificationsFollowed`,`notificationsReblogged`,`notificationsFavorited`,`notificationSound`,`notificationVibration`,`notificationLight`,`lastNotificationId`,`activeNotifications`) VALUES (nullif(?, 0),?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
      }

      @Override
      public void bind(SupportSQLiteStatement stmt, AccountEntity value) {
        stmt.bindLong(1, value.getId());
        if (value.getDomain() == null) {
          stmt.bindNull(2);
        } else {
          stmt.bindString(2, value.getDomain());
        }
        if (value.getAccessToken() == null) {
          stmt.bindNull(3);
        } else {
          stmt.bindString(3, value.getAccessToken());
        }
        final int _tmp;
        _tmp = value.isActive() ? 1 : 0;
        stmt.bindLong(4, _tmp);
        if (value.getAccountId() == null) {
          stmt.bindNull(5);
        } else {
          stmt.bindString(5, value.getAccountId());
        }
        if (value.getUsername() == null) {
          stmt.bindNull(6);
        } else {
          stmt.bindString(6, value.getUsername());
        }
        if (value.getDisplayName() == null) {
          stmt.bindNull(7);
        } else {
          stmt.bindString(7, value.getDisplayName());
        }
        if (value.getProfilePictureUrl() == null) {
          stmt.bindNull(8);
        } else {
          stmt.bindString(8, value.getProfilePictureUrl());
        }
        final int _tmp_1;
        _tmp_1 = value.getNotificationsEnabled() ? 1 : 0;
        stmt.bindLong(9, _tmp_1);
        final int _tmp_2;
        _tmp_2 = value.getNotificationsMentioned() ? 1 : 0;
        stmt.bindLong(10, _tmp_2);
        final int _tmp_3;
        _tmp_3 = value.getNotificationsFollowed() ? 1 : 0;
        stmt.bindLong(11, _tmp_3);
        final int _tmp_4;
        _tmp_4 = value.getNotificationsReblogged() ? 1 : 0;
        stmt.bindLong(12, _tmp_4);
        final int _tmp_5;
        _tmp_5 = value.getNotificationsFavorited() ? 1 : 0;
        stmt.bindLong(13, _tmp_5);
        final int _tmp_6;
        _tmp_6 = value.getNotificationSound() ? 1 : 0;
        stmt.bindLong(14, _tmp_6);
        final int _tmp_7;
        _tmp_7 = value.getNotificationVibration() ? 1 : 0;
        stmt.bindLong(15, _tmp_7);
        final int _tmp_8;
        _tmp_8 = value.getNotificationLight() ? 1 : 0;
        stmt.bindLong(16, _tmp_8);
        if (value.getLastNotificationId() == null) {
          stmt.bindNull(17);
        } else {
          stmt.bindString(17, value.getLastNotificationId());
        }
        if (value.getActiveNotifications() == null) {
          stmt.bindNull(18);
        } else {
          stmt.bindString(18, value.getActiveNotifications());
        }
      }
    };
    this.__deletionAdapterOfAccountEntity = new EntityDeletionOrUpdateAdapter<AccountEntity>(__db) {
      @Override
      public String createQuery() {
        return "DELETE FROM `AccountEntity` WHERE `id` = ?";
      }

      @Override
      public void bind(SupportSQLiteStatement stmt, AccountEntity value) {
        stmt.bindLong(1, value.getId());
      }
    };
  }

  @Override
  public long insertOrReplace(AccountEntity account) {
    __db.beginTransaction();
    try {
      long _result = __insertionAdapterOfAccountEntity.insertAndReturnId(account);
      __db.setTransactionSuccessful();
      return _result;
    } finally {
      __db.endTransaction();
    }
  }

  @Override
  public void delete(AccountEntity account) {
    __db.beginTransaction();
    try {
      __deletionAdapterOfAccountEntity.handle(account);
      __db.setTransactionSuccessful();
    } finally {
      __db.endTransaction();
    }
  }

  @Override
  public List<AccountEntity> loadAll() {
    final String _sql = "SELECT * FROM AccountEntity ORDER BY id ASC";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 0);
    final Cursor _cursor = __db.query(_statement);
    try {
      final int _cursorIndexOfId = _cursor.getColumnIndexOrThrow("id");
      final int _cursorIndexOfDomain = _cursor.getColumnIndexOrThrow("domain");
      final int _cursorIndexOfAccessToken = _cursor.getColumnIndexOrThrow("accessToken");
      final int _cursorIndexOfIsActive = _cursor.getColumnIndexOrThrow("isActive");
      final int _cursorIndexOfAccountId = _cursor.getColumnIndexOrThrow("accountId");
      final int _cursorIndexOfUsername = _cursor.getColumnIndexOrThrow("username");
      final int _cursorIndexOfDisplayName = _cursor.getColumnIndexOrThrow("displayName");
      final int _cursorIndexOfProfilePictureUrl = _cursor.getColumnIndexOrThrow("profilePictureUrl");
      final int _cursorIndexOfNotificationsEnabled = _cursor.getColumnIndexOrThrow("notificationsEnabled");
      final int _cursorIndexOfNotificationsMentioned = _cursor.getColumnIndexOrThrow("notificationsMentioned");
      final int _cursorIndexOfNotificationsFollowed = _cursor.getColumnIndexOrThrow("notificationsFollowed");
      final int _cursorIndexOfNotificationsReblogged = _cursor.getColumnIndexOrThrow("notificationsReblogged");
      final int _cursorIndexOfNotificationsFavorited = _cursor.getColumnIndexOrThrow("notificationsFavorited");
      final int _cursorIndexOfNotificationSound = _cursor.getColumnIndexOrThrow("notificationSound");
      final int _cursorIndexOfNotificationVibration = _cursor.getColumnIndexOrThrow("notificationVibration");
      final int _cursorIndexOfNotificationLight = _cursor.getColumnIndexOrThrow("notificationLight");
      final int _cursorIndexOfLastNotificationId = _cursor.getColumnIndexOrThrow("lastNotificationId");
      final int _cursorIndexOfActiveNotifications = _cursor.getColumnIndexOrThrow("activeNotifications");
      final List<AccountEntity> _result = new ArrayList<AccountEntity>(_cursor.getCount());
      while(_cursor.moveToNext()) {
        final AccountEntity _item;
        final long _tmpId;
        _tmpId = _cursor.getLong(_cursorIndexOfId);
        final String _tmpDomain;
        _tmpDomain = _cursor.getString(_cursorIndexOfDomain);
        final String _tmpAccessToken;
        _tmpAccessToken = _cursor.getString(_cursorIndexOfAccessToken);
        final boolean _tmpIsActive;
        final int _tmp;
        _tmp = _cursor.getInt(_cursorIndexOfIsActive);
        _tmpIsActive = _tmp != 0;
        final String _tmpAccountId;
        _tmpAccountId = _cursor.getString(_cursorIndexOfAccountId);
        final String _tmpUsername;
        _tmpUsername = _cursor.getString(_cursorIndexOfUsername);
        final String _tmpDisplayName;
        _tmpDisplayName = _cursor.getString(_cursorIndexOfDisplayName);
        final String _tmpProfilePictureUrl;
        _tmpProfilePictureUrl = _cursor.getString(_cursorIndexOfProfilePictureUrl);
        final boolean _tmpNotificationsEnabled;
        final int _tmp_1;
        _tmp_1 = _cursor.getInt(_cursorIndexOfNotificationsEnabled);
        _tmpNotificationsEnabled = _tmp_1 != 0;
        final boolean _tmpNotificationsMentioned;
        final int _tmp_2;
        _tmp_2 = _cursor.getInt(_cursorIndexOfNotificationsMentioned);
        _tmpNotificationsMentioned = _tmp_2 != 0;
        final boolean _tmpNotificationsFollowed;
        final int _tmp_3;
        _tmp_3 = _cursor.getInt(_cursorIndexOfNotificationsFollowed);
        _tmpNotificationsFollowed = _tmp_3 != 0;
        final boolean _tmpNotificationsReblogged;
        final int _tmp_4;
        _tmp_4 = _cursor.getInt(_cursorIndexOfNotificationsReblogged);
        _tmpNotificationsReblogged = _tmp_4 != 0;
        final boolean _tmpNotificationsFavorited;
        final int _tmp_5;
        _tmp_5 = _cursor.getInt(_cursorIndexOfNotificationsFavorited);
        _tmpNotificationsFavorited = _tmp_5 != 0;
        final boolean _tmpNotificationSound;
        final int _tmp_6;
        _tmp_6 = _cursor.getInt(_cursorIndexOfNotificationSound);
        _tmpNotificationSound = _tmp_6 != 0;
        final boolean _tmpNotificationVibration;
        final int _tmp_7;
        _tmp_7 = _cursor.getInt(_cursorIndexOfNotificationVibration);
        _tmpNotificationVibration = _tmp_7 != 0;
        final boolean _tmpNotificationLight;
        final int _tmp_8;
        _tmp_8 = _cursor.getInt(_cursorIndexOfNotificationLight);
        _tmpNotificationLight = _tmp_8 != 0;
        final String _tmpLastNotificationId;
        _tmpLastNotificationId = _cursor.getString(_cursorIndexOfLastNotificationId);
        final String _tmpActiveNotifications;
        _tmpActiveNotifications = _cursor.getString(_cursorIndexOfActiveNotifications);
        _item = new AccountEntity(_tmpId,_tmpDomain,_tmpAccessToken,_tmpIsActive,_tmpAccountId,_tmpUsername,_tmpDisplayName,_tmpProfilePictureUrl,_tmpNotificationsEnabled,_tmpNotificationsMentioned,_tmpNotificationsFollowed,_tmpNotificationsReblogged,_tmpNotificationsFavorited,_tmpNotificationSound,_tmpNotificationVibration,_tmpNotificationLight,_tmpLastNotificationId,_tmpActiveNotifications);
        _result.add(_item);
      }
      return _result;
    } finally {
      _cursor.close();
      _statement.release();
    }
  }
}
