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.collections.MutableList
import kotlin.collections.mutableListOf
import kotlin.reflect.KClass
import world.respect.datalayer.db.school.SchoolTypeConverters
import world.respect.datalayer.db.school.xapi.entities.XapiActivityInteractionEntity
import world.respect.datalayer.db.school.xapi.entities.XapiActivityInteractionEntityPropEnum

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

  private val __insertAdapterOfXapiActivityInteractionEntity:
      EntityInsertAdapter<XapiActivityInteractionEntity>

  private val __schoolTypeConverters: SchoolTypeConverters = SchoolTypeConverters()
  init {
    this.__db = __db
    this.__insertAdapterOfXapiActivityInteractionEntity = object : EntityInsertAdapter<XapiActivityInteractionEntity>() {
      protected override fun createQuery(): String = "INSERT OR IGNORE INTO `XapiActivityInteractionEntity` (`aieUid`,`aieActivityUid`,`aieProp`,`aieId`) VALUES (nullif(?, 0),?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiActivityInteractionEntity) {
        statement.bindLong(1, entity.aieUid)
        statement.bindLong(2, entity.aieActivityUid)
        val _tmp: Int = __schoolTypeConverters.fromActivityInteractionEntityPropEnum(entity.aieProp)
        statement.bindLong(3, _tmp.toLong())
        statement.bindText(4, entity.aieId)
      }
    }
  }

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

  public override suspend fun findAllByActivityUidAsync(activityUid: Long): List<XapiActivityInteractionEntity> {
    val _sql: String = """
        |
        |        SELECT XapiActivityInteractionEntity.*
        |          FROM XapiActivityInteractionEntity
        |         WHERE XapiActivityInteractionEntity.aieActivityUid = ? 
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, activityUid)
        val _columnIndexOfAieUid: Int = getColumnIndexOrThrow(_stmt, "aieUid")
        val _columnIndexOfAieActivityUid: Int = getColumnIndexOrThrow(_stmt, "aieActivityUid")
        val _columnIndexOfAieProp: Int = getColumnIndexOrThrow(_stmt, "aieProp")
        val _columnIndexOfAieId: Int = getColumnIndexOrThrow(_stmt, "aieId")
        val _result: MutableList<XapiActivityInteractionEntity> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiActivityInteractionEntity
          val _tmpAieUid: Long
          _tmpAieUid = _stmt.getLong(_columnIndexOfAieUid)
          val _tmpAieActivityUid: Long
          _tmpAieActivityUid = _stmt.getLong(_columnIndexOfAieActivityUid)
          val _tmpAieProp: XapiActivityInteractionEntityPropEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfAieProp).toInt()
          _tmpAieProp = __schoolTypeConverters.toActivityInteractionEntityPropEnum(_tmp)
          val _tmpAieId: String
          _tmpAieId = _stmt.getText(_columnIndexOfAieId)
          _item = XapiActivityInteractionEntity(_tmpAieUid,_tmpAieActivityUid,_tmpAieProp,_tmpAieId)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun deleteByActivityUid(activityUid: Long) {
    val _sql: String = """
        |
        |        DELETE FROM XapiActivityInteractionEntity 
        |         WHERE aieActivityUid = ?
        |    
        """.trimMargin()
    return performSuspending(__db, false, true) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, activityUid)
        _stmt.step()
      } finally {
        _stmt.close()
      }
    }
  }

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