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.Unit
import kotlin.collections.List
import kotlin.reflect.KClass
import world.respect.datalayer.db.school.SchoolTypeConverters
import world.respect.datalayer.db.school.xapi.entities.XapiVerbEntity
import world.respect.datalayer.school.model.StatusEnum

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

  private val __insertAdapterOfXapiVerbEntity: EntityInsertAdapter<XapiVerbEntity>

  private val __schoolTypeConverters: SchoolTypeConverters = SchoolTypeConverters()
  init {
    this.__db = __db
    this.__insertAdapterOfXapiVerbEntity = object : EntityInsertAdapter<XapiVerbEntity>() {
      protected override fun createQuery(): String = "INSERT OR IGNORE INTO `XapiVerbEntity` (`verbUid`,`verbUrlId`,`verbStatus`,`verbLct`) VALUES (?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiVerbEntity) {
        statement.bindLong(1, entity.verbUid)
        statement.bindText(2, entity.verbUrlId)
        val _tmp: Int = __schoolTypeConverters.fromStatusEnum(entity.verbStatus)
        statement.bindLong(3, _tmp.toLong())
        statement.bindLong(4, entity.verbLct)
      }
    }
  }

  public override suspend fun insertOrIgnoreAsync(entities: List<XapiVerbEntity>): Unit = performSuspending(__db, false, true) { _connection ->
    __insertAdapterOfXapiVerbEntity.insert(_connection, entities)
  }

  public override suspend fun findByUid(uid: Long): XapiVerbEntity? {
    val _sql: String = """
        |
        |        SELECT XapiVerbEntity.*
        |        FROM XapiVerbEntity
        |        WHERE XapiVerbEntity.verbUid = ? 
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, uid)
        val _columnIndexOfVerbUid: Int = getColumnIndexOrThrow(_stmt, "verbUid")
        val _columnIndexOfVerbUrlId: Int = getColumnIndexOrThrow(_stmt, "verbUrlId")
        val _columnIndexOfVerbStatus: Int = getColumnIndexOrThrow(_stmt, "verbStatus")
        val _columnIndexOfVerbLct: Int = getColumnIndexOrThrow(_stmt, "verbLct")
        val _result: XapiVerbEntity?
        if (_stmt.step()) {
          val _tmpVerbUid: Long
          _tmpVerbUid = _stmt.getLong(_columnIndexOfVerbUid)
          val _tmpVerbUrlId: String
          _tmpVerbUrlId = _stmt.getText(_columnIndexOfVerbUrlId)
          val _tmpVerbStatus: StatusEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfVerbStatus).toInt()
          _tmpVerbStatus = __schoolTypeConverters.toStatusEnum(_tmp)
          val _tmpVerbLct: Long
          _tmpVerbLct = _stmt.getLong(_columnIndexOfVerbLct)
          _result = XapiVerbEntity(_tmpVerbUid,_tmpVerbUrlId,_tmpVerbStatus,_tmpVerbLct)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

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