package world.respect.datalayer.db.school.xapi.daos

import androidx.room.EntityInsertAdapter
import androidx.room.RoomDatabase
import androidx.room.util.getColumnIndexOrThrow
import androidx.room.util.performSuspending
import androidx.sqlite.SQLiteStatement
import javax.`annotation`.processing.Generated
import kotlin.Int
import kotlin.Long
import kotlin.String
import kotlin.Suppress
import kotlin.collections.List
import kotlin.reflect.KClass
import world.respect.datalayer.db.school.xapi.entities.XapiSessionEntity

@Generated(value = ["androidx.room.RoomProcessor"])
@Suppress(names = ["UNCHECKED_CAST", "DEPRECATION", "REDUNDANT_PROJECTION", "REMOVAL"])
public class XapiSessionEntityDao_Impl(
  __db: RoomDatabase,
) : XapiSessionEntityDao {
  private val __db: RoomDatabase

  private val __insertAdapterOfXapiSessionEntity: EntityInsertAdapter<XapiSessionEntity>
  init {
    this.__db = __db
    this.__insertAdapterOfXapiSessionEntity = object : EntityInsertAdapter<XapiSessionEntity>() {
      protected override fun createQuery(): String = "INSERT OR ABORT INTO `XapiSessionEntity` (`xseUid`,`xseRegistrationHi`,`xseRegistrationLo`,`xseAccountPersonUid`,`xseActorUid`,`xseStartTime`,`xseExpireTime`,`xseAuth`) VALUES (nullif(?, 0),?,?,?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiSessionEntity) {
        statement.bindLong(1, entity.xseUid)
        statement.bindLong(2, entity.xseRegistrationHi)
        statement.bindLong(3, entity.xseRegistrationLo)
        statement.bindText(4, entity.xseAccountPersonUid)
        statement.bindLong(5, entity.xseActorUid)
        statement.bindLong(6, entity.xseStartTime)
        statement.bindLong(7, entity.xseExpireTime)
        statement.bindText(8, entity.xseAuth)
      }
    }
  }

  public override suspend fun insertAsync(xapiSessionEntity: XapiSessionEntity): Long = performSuspending(__db, false, true) { _connection ->
    val _result: Long = __insertAdapterOfXapiSessionEntity.insertAndReturnId(_connection, xapiSessionEntity)
    _result
  }

  public override suspend fun findByUidAsync(uid: Long): XapiSessionEntity? {
    val _sql: String = """
        |
        |        SELECT XapiSessionEntity.*
        |          FROM XapiSessionEntity
        |         WHERE XapiSessionEntity.xseUid = ?
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, uid)
        val _columnIndexOfXseUid: Int = getColumnIndexOrThrow(_stmt, "xseUid")
        val _columnIndexOfXseRegistrationHi: Int = getColumnIndexOrThrow(_stmt, "xseRegistrationHi")
        val _columnIndexOfXseRegistrationLo: Int = getColumnIndexOrThrow(_stmt, "xseRegistrationLo")
        val _columnIndexOfXseAccountPersonUid: Int = getColumnIndexOrThrow(_stmt, "xseAccountPersonUid")
        val _columnIndexOfXseActorUid: Int = getColumnIndexOrThrow(_stmt, "xseActorUid")
        val _columnIndexOfXseStartTime: Int = getColumnIndexOrThrow(_stmt, "xseStartTime")
        val _columnIndexOfXseExpireTime: Int = getColumnIndexOrThrow(_stmt, "xseExpireTime")
        val _columnIndexOfXseAuth: Int = getColumnIndexOrThrow(_stmt, "xseAuth")
        val _result: XapiSessionEntity?
        if (_stmt.step()) {
          val _tmpXseUid: Long
          _tmpXseUid = _stmt.getLong(_columnIndexOfXseUid)
          val _tmpXseRegistrationHi: Long
          _tmpXseRegistrationHi = _stmt.getLong(_columnIndexOfXseRegistrationHi)
          val _tmpXseRegistrationLo: Long
          _tmpXseRegistrationLo = _stmt.getLong(_columnIndexOfXseRegistrationLo)
          val _tmpXseAccountPersonUid: String
          _tmpXseAccountPersonUid = _stmt.getText(_columnIndexOfXseAccountPersonUid)
          val _tmpXseActorUid: Long
          _tmpXseActorUid = _stmt.getLong(_columnIndexOfXseActorUid)
          val _tmpXseStartTime: Long
          _tmpXseStartTime = _stmt.getLong(_columnIndexOfXseStartTime)
          val _tmpXseExpireTime: Long
          _tmpXseExpireTime = _stmt.getLong(_columnIndexOfXseExpireTime)
          val _tmpXseAuth: String
          _tmpXseAuth = _stmt.getText(_columnIndexOfXseAuth)
          _result = XapiSessionEntity(_tmpXseUid,_tmpXseRegistrationHi,_tmpXseRegistrationLo,_tmpXseAccountPersonUid,_tmpXseActorUid,_tmpXseStartTime,_tmpXseExpireTime,_tmpXseAuth)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public companion object {
    public fun getRequiredConverters(): List<KClass<*>> = emptyList()
  }
}
