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.Boolean
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.xapi.entities.XapiActivityExtensionEntity

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

  private val __insertAdapterOfXapiActivityExtensionEntity:
      EntityInsertAdapter<XapiActivityExtensionEntity>
  init {
    this.__db = __db
    this.__insertAdapterOfXapiActivityExtensionEntity = object : EntityInsertAdapter<XapiActivityExtensionEntity>() {
      protected override fun createQuery(): String = "INSERT OR REPLACE INTO `XapiActivityExtensionEntity` (`aeeActivityUid`,`aeeKeyHash`,`aeeKey`,`aeeJson`,`aeeLastMod`,`aeeIsDeleted`) VALUES (?,?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiActivityExtensionEntity) {
        statement.bindLong(1, entity.aeeActivityUid)
        statement.bindLong(2, entity.aeeKeyHash)
        statement.bindText(3, entity.aeeKey)
        statement.bindText(4, entity.aeeJson)
        statement.bindLong(5, entity.aeeLastMod)
        val _tmp: Int = if (entity.aeeIsDeleted) 1 else 0
        statement.bindLong(6, _tmp.toLong())
      }
    }
  }

  public override suspend fun upsertListAsync(list: List<XapiActivityExtensionEntity>): Unit = performSuspending(__db, false, true) { _connection ->
    __insertAdapterOfXapiActivityExtensionEntity.insert(_connection, list)
  }

  public override suspend fun findAllByActivityUid(activityUid: Long): List<XapiActivityExtensionEntity> {
    val _sql: String = """
        |
        |        SELECT XapiActivityExtensionEntity.*
        |          FROM XapiActivityExtensionEntity
        |         WHERE XapiActivityExtensionEntity.aeeActivityUid = ? 
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, activityUid)
        val _columnIndexOfAeeActivityUid: Int = getColumnIndexOrThrow(_stmt, "aeeActivityUid")
        val _columnIndexOfAeeKeyHash: Int = getColumnIndexOrThrow(_stmt, "aeeKeyHash")
        val _columnIndexOfAeeKey: Int = getColumnIndexOrThrow(_stmt, "aeeKey")
        val _columnIndexOfAeeJson: Int = getColumnIndexOrThrow(_stmt, "aeeJson")
        val _columnIndexOfAeeLastMod: Int = getColumnIndexOrThrow(_stmt, "aeeLastMod")
        val _columnIndexOfAeeIsDeleted: Int = getColumnIndexOrThrow(_stmt, "aeeIsDeleted")
        val _result: MutableList<XapiActivityExtensionEntity> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiActivityExtensionEntity
          val _tmpAeeActivityUid: Long
          _tmpAeeActivityUid = _stmt.getLong(_columnIndexOfAeeActivityUid)
          val _tmpAeeKeyHash: Long
          _tmpAeeKeyHash = _stmt.getLong(_columnIndexOfAeeKeyHash)
          val _tmpAeeKey: String
          _tmpAeeKey = _stmt.getText(_columnIndexOfAeeKey)
          val _tmpAeeJson: String
          _tmpAeeJson = _stmt.getText(_columnIndexOfAeeJson)
          val _tmpAeeLastMod: Long
          _tmpAeeLastMod = _stmt.getLong(_columnIndexOfAeeLastMod)
          val _tmpAeeIsDeleted: Boolean
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfAeeIsDeleted).toInt()
          _tmpAeeIsDeleted = _tmp != 0
          _item = XapiActivityExtensionEntity(_tmpAeeActivityUid,_tmpAeeKeyHash,_tmpAeeKey,_tmpAeeJson,_tmpAeeLastMod,_tmpAeeIsDeleted)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun deleteByActivityUid(activityUid: Long) {
    val _sql: String = """
        |
        |        DELETE FROM XapiActivityExtensionEntity 
        |              WHERE aeeActivityUid = ?
        |    
        """.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()
  }
}
