package hanson.xyz.vpnhotspotmod.room;

import android.database.Cursor;
import android.net.MacAddress;
import android.os.CancellationSignal;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.room.CoroutinesRoom;
import androidx.room.EntityInsertionAdapter;
import androidx.room.RoomDatabase;
import androidx.room.RoomDatabaseKt;
import androidx.room.RoomSQLiteQuery;
import androidx.room.util.CursorUtil;
import androidx.room.util.DBUtil;
import androidx.sqlite.db.SupportSQLiteStatement;
import java.lang.CharSequence;
import java.lang.Class;
import java.lang.Exception;
import java.lang.Long;
import java.lang.Object;
import java.lang.Override;
import java.lang.String;
import java.lang.SuppressWarnings;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import javax.annotation.processing.Generated;
import kotlin.Unit;
import kotlin.coroutines.Continuation;
import kotlin.jvm.functions.Function2;

@Generated("androidx.room.RoomProcessor")
@SuppressWarnings({"unchecked", "deprecation"})
public final class ClientRecord_Dao_Impl extends ClientRecord.Dao {
  private final RoomDatabase __db;

  private final EntityInsertionAdapter<ClientRecord> __insertionAdapterOfClientRecord;

  public ClientRecord_Dao_Impl(@NonNull final RoomDatabase __db) {
    this.__db = __db;
    this.__insertionAdapterOfClientRecord = new EntityInsertionAdapter<ClientRecord>(__db) {
      @Override
      @NonNull
      protected String createQuery() {
        return "INSERT OR REPLACE INTO `ClientRecord` (`mac`,`nickname`,`blocked`,`macLookupPending`) VALUES (?,?,?,?)";
      }

      @Override
      protected void bind(@NonNull final SupportSQLiteStatement statement,
          @NonNull final ClientRecord entity) {
        final long _tmp = Converters.INSTANCE.persistMacAddress(entity.getMac());
        statement.bindLong(1, _tmp);
        final byte[] _tmp_1 = Converters.INSTANCE.persistCharSequence(entity.getNickname());
        if (_tmp_1 == null) {
          statement.bindNull(2);
        } else {
          statement.bindBlob(2, _tmp_1);
        }
        final int _tmp_2 = entity.getBlocked() ? 1 : 0;
        statement.bindLong(3, _tmp_2);
        final int _tmp_3 = entity.getMacLookupPending() ? 1 : 0;
        statement.bindLong(4, _tmp_3);
      }
    };
  }

  @Override
  protected Object updateInternal(final ClientRecord value,
      final Continuation<? super Long> $completion) {
    return CoroutinesRoom.execute(__db, true, new Callable<Long>() {
      @Override
      @NonNull
      public Long call() throws Exception {
        __db.beginTransaction();
        try {
          final Long _result = __insertionAdapterOfClientRecord.insertAndReturnId(value);
          __db.setTransactionSuccessful();
          return _result;
        } finally {
          __db.endTransaction();
        }
      }
    }, $completion);
  }

  @Override
  public Object upsert(final MacAddress mac,
      final Function2<? super ClientRecord, ? super Continuation<? super Unit>, ?> operation,
      final Continuation<? super ClientRecord> $completion) {
    return RoomDatabaseKt.withTransaction(__db, (__cont) -> ClientRecord_Dao_Impl.super.upsert(mac, operation, __cont), $completion);
  }

  @Override
  protected ClientRecord lookupBlocking(final MacAddress mac) {
    final String _sql = "SELECT * FROM `ClientRecord` WHERE `mac` = ?";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 1);
    int _argIndex = 1;
    final long _tmp = Converters.INSTANCE.persistMacAddress(mac);
    _statement.bindLong(_argIndex, _tmp);
    __db.assertNotSuspendingTransaction();
    final Cursor _cursor = DBUtil.query(__db, _statement, false, null);
    try {
      final int _cursorIndexOfMac = CursorUtil.getColumnIndexOrThrow(_cursor, "mac");
      final int _cursorIndexOfNickname = CursorUtil.getColumnIndexOrThrow(_cursor, "nickname");
      final int _cursorIndexOfBlocked = CursorUtil.getColumnIndexOrThrow(_cursor, "blocked");
      final int _cursorIndexOfMacLookupPending = CursorUtil.getColumnIndexOrThrow(_cursor, "macLookupPending");
      final ClientRecord _result;
      if (_cursor.moveToFirst()) {
        final MacAddress _tmpMac;
        final long _tmp_1;
        _tmp_1 = _cursor.getLong(_cursorIndexOfMac);
        _tmpMac = Converters.INSTANCE.unpersistMacAddress(_tmp_1);
        final CharSequence _tmpNickname;
        final byte[] _tmp_2;
        if (_cursor.isNull(_cursorIndexOfNickname)) {
          _tmp_2 = null;
        } else {
          _tmp_2 = _cursor.getBlob(_cursorIndexOfNickname);
        }
        _tmpNickname = Converters.INSTANCE.unpersistCharSequence(_tmp_2);
        final boolean _tmpBlocked;
        final int _tmp_3;
        _tmp_3 = _cursor.getInt(_cursorIndexOfBlocked);
        _tmpBlocked = _tmp_3 != 0;
        final boolean _tmpMacLookupPending;
        final int _tmp_4;
        _tmp_4 = _cursor.getInt(_cursorIndexOfMacLookupPending);
        _tmpMacLookupPending = _tmp_4 != 0;
        _result = new ClientRecord(_tmpMac,_tmpNickname,_tmpBlocked,_tmpMacLookupPending);
      } else {
        _result = null;
      }
      return _result;
    } finally {
      _cursor.close();
      _statement.release();
    }
  }

  @Override
  protected Object lookup(final MacAddress mac,
      final Continuation<? super ClientRecord> $completion) {
    final String _sql = "SELECT * FROM `ClientRecord` WHERE `mac` = ?";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 1);
    int _argIndex = 1;
    final long _tmp = Converters.INSTANCE.persistMacAddress(mac);
    _statement.bindLong(_argIndex, _tmp);
    final CancellationSignal _cancellationSignal = DBUtil.createCancellationSignal();
    return CoroutinesRoom.execute(__db, false, _cancellationSignal, new Callable<ClientRecord>() {
      @Override
      @Nullable
      public ClientRecord call() throws Exception {
        final Cursor _cursor = DBUtil.query(__db, _statement, false, null);
        try {
          final int _cursorIndexOfMac = CursorUtil.getColumnIndexOrThrow(_cursor, "mac");
          final int _cursorIndexOfNickname = CursorUtil.getColumnIndexOrThrow(_cursor, "nickname");
          final int _cursorIndexOfBlocked = CursorUtil.getColumnIndexOrThrow(_cursor, "blocked");
          final int _cursorIndexOfMacLookupPending = CursorUtil.getColumnIndexOrThrow(_cursor, "macLookupPending");
          final ClientRecord _result;
          if (_cursor.moveToFirst()) {
            final MacAddress _tmpMac;
            final long _tmp_1;
            _tmp_1 = _cursor.getLong(_cursorIndexOfMac);
            _tmpMac = Converters.INSTANCE.unpersistMacAddress(_tmp_1);
            final CharSequence _tmpNickname;
            final byte[] _tmp_2;
            if (_cursor.isNull(_cursorIndexOfNickname)) {
              _tmp_2 = null;
            } else {
              _tmp_2 = _cursor.getBlob(_cursorIndexOfNickname);
            }
            _tmpNickname = Converters.INSTANCE.unpersistCharSequence(_tmp_2);
            final boolean _tmpBlocked;
            final int _tmp_3;
            _tmp_3 = _cursor.getInt(_cursorIndexOfBlocked);
            _tmpBlocked = _tmp_3 != 0;
            final boolean _tmpMacLookupPending;
            final int _tmp_4;
            _tmp_4 = _cursor.getInt(_cursorIndexOfMacLookupPending);
            _tmpMacLookupPending = _tmp_4 != 0;
            _result = new ClientRecord(_tmpMac,_tmpNickname,_tmpBlocked,_tmpMacLookupPending);
          } else {
            _result = null;
          }
          return _result;
        } finally {
          _cursor.close();
          _statement.release();
        }
      }
    }, $completion);
  }

  @Override
  protected LiveData<ClientRecord> lookupSync(final MacAddress mac) {
    final String _sql = "SELECT * FROM `ClientRecord` WHERE `mac` = ?";
    final RoomSQLiteQuery _statement = RoomSQLiteQuery.acquire(_sql, 1);
    int _argIndex = 1;
    final long _tmp = Converters.INSTANCE.persistMacAddress(mac);
    _statement.bindLong(_argIndex, _tmp);
    return __db.getInvalidationTracker().createLiveData(new String[] {"ClientRecord"}, false, new Callable<ClientRecord>() {
      @Override
      @Nullable
      public ClientRecord call() throws Exception {
        final Cursor _cursor = DBUtil.query(__db, _statement, false, null);
        try {
          final int _cursorIndexOfMac = CursorUtil.getColumnIndexOrThrow(_cursor, "mac");
          final int _cursorIndexOfNickname = CursorUtil.getColumnIndexOrThrow(_cursor, "nickname");
          final int _cursorIndexOfBlocked = CursorUtil.getColumnIndexOrThrow(_cursor, "blocked");
          final int _cursorIndexOfMacLookupPending = CursorUtil.getColumnIndexOrThrow(_cursor, "macLookupPending");
          final ClientRecord _result;
          if (_cursor.moveToFirst()) {
            final MacAddress _tmpMac;
            final long _tmp_1;
            _tmp_1 = _cursor.getLong(_cursorIndexOfMac);
            _tmpMac = Converters.INSTANCE.unpersistMacAddress(_tmp_1);
            final CharSequence _tmpNickname;
            final byte[] _tmp_2;
            if (_cursor.isNull(_cursorIndexOfNickname)) {
              _tmp_2 = null;
            } else {
              _tmp_2 = _cursor.getBlob(_cursorIndexOfNickname);
            }
            _tmpNickname = Converters.INSTANCE.unpersistCharSequence(_tmp_2);
            final boolean _tmpBlocked;
            final int _tmp_3;
            _tmp_3 = _cursor.getInt(_cursorIndexOfBlocked);
            _tmpBlocked = _tmp_3 != 0;
            final boolean _tmpMacLookupPending;
            final int _tmp_4;
            _tmp_4 = _cursor.getInt(_cursorIndexOfMacLookupPending);
            _tmpMacLookupPending = _tmp_4 != 0;
            _result = new ClientRecord(_tmpMac,_tmpNickname,_tmpBlocked,_tmpMacLookupPending);
          } else {
            _result = null;
          }
          return _result;
        } finally {
          _cursor.close();
        }
      }

      @Override
      protected void finalize() {
        _statement.release();
      }
    });
  }

  @NonNull
  public static List<Class<?>> getRequiredConverters() {
    return Collections.emptyList();
  }
}
