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

import androidx.collection.LongSparseArray
import androidx.room.EntityInsertAdapter
import androidx.room.RoomDatabase
import androidx.room.util.appendPlaceholders
import androidx.room.util.getColumnIndex
import androidx.room.util.getColumnIndexOrThrow
import androidx.room.util.performSuspending
import androidx.room.util.recursiveFetchLongSparseArray
import androidx.sqlite.SQLiteConnection
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 kotlin.text.StringBuilder
import kotlin.time.Instant
import world.respect.datalayer.db.school.SchoolTypeConverters
import world.respect.datalayer.db.school.xapi.adapters.XapiActivityEntities
import world.respect.datalayer.db.school.xapi.entities.XapiActivityEntity
import world.respect.datalayer.db.school.xapi.entities.XapiActivityExtensionEntity
import world.respect.datalayer.db.school.xapi.entities.XapiActivityInteractionEntity
import world.respect.datalayer.db.school.xapi.entities.XapiActivityInteractionEntityPropEnum
import world.respect.datalayer.db.school.xapi.entities.XapiActivityLangMapEntry
import world.respect.datalayer.db.school.xapi.entities.XapiActivityLangMapEntryPropEnum
import world.respect.datalayer.db.shared.SharedConverters
import world.respect.lib.xapi.model.XapiInteractionTypeEnum

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

  private val __insertAdapterOfXapiActivityEntity: EntityInsertAdapter<XapiActivityEntity>

  private val __schoolTypeConverters: SchoolTypeConverters = SchoolTypeConverters()

  private val __sharedConverters: SharedConverters = SharedConverters()

  private val __insertAdapterOfXapiActivityEntity_1: EntityInsertAdapter<XapiActivityEntity>
  init {
    this.__db = __db
    this.__insertAdapterOfXapiActivityEntity = object : EntityInsertAdapter<XapiActivityEntity>() {
      protected override fun createQuery(): String = "INSERT OR IGNORE INTO `XapiActivityEntity` (`actUid`,`actIdIri`,`actType`,`actMoreInfo`,`actInteractionType`,`actCorrectResponsePatterns`,`actNonSignificantLastModified`,`actSignificantLastModified`,`actStored`,`actFlags`,`actObjectTypeSet`) VALUES (?,?,?,?,?,?,?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiActivityEntity) {
        statement.bindLong(1, entity.actUid)
        statement.bindText(2, entity.actIdIri)
        val _tmpActType: String? = entity.actType
        if (_tmpActType == null) {
          statement.bindNull(3)
        } else {
          statement.bindText(3, _tmpActType)
        }
        val _tmpActMoreInfo: String? = entity.actMoreInfo
        if (_tmpActMoreInfo == null) {
          statement.bindNull(4)
        } else {
          statement.bindText(4, _tmpActMoreInfo)
        }
        val _tmpActInteractionType: XapiInteractionTypeEnum? = entity.actInteractionType
        val _tmp: Int?
        if (_tmpActInteractionType == null) {
          _tmp = null
        } else {
          _tmp = __schoolTypeConverters.fromXapiInteractionTypeEnum(_tmpActInteractionType)
        }
        if (_tmp == null) {
          statement.bindNull(5)
        } else {
          statement.bindLong(5, _tmp.toLong())
        }
        val _tmpActCorrectResponsePatterns: String? = entity.actCorrectResponsePatterns
        if (_tmpActCorrectResponsePatterns == null) {
          statement.bindNull(6)
        } else {
          statement.bindText(6, _tmpActCorrectResponsePatterns)
        }
        val _tmp_1: Long? = __sharedConverters.fromInstant(entity.actNonSignificantLastModified)
        if (_tmp_1 == null) {
          statement.bindNull(7)
        } else {
          statement.bindLong(7, _tmp_1)
        }
        val _tmp_2: Long? = __sharedConverters.fromInstant(entity.actSignificantLastModified)
        if (_tmp_2 == null) {
          statement.bindNull(8)
        } else {
          statement.bindLong(8, _tmp_2)
        }
        val _tmp_3: Long? = __sharedConverters.fromInstant(entity.actStored)
        if (_tmp_3 == null) {
          statement.bindNull(9)
        } else {
          statement.bindLong(9, _tmp_3)
        }
        statement.bindLong(10, entity.actFlags.toLong())
        val _tmp_4: Int = if (entity.actObjectTypeSet) 1 else 0
        statement.bindLong(11, _tmp_4.toLong())
      }
    }
    this.__insertAdapterOfXapiActivityEntity_1 = object : EntityInsertAdapter<XapiActivityEntity>() {
      protected override fun createQuery(): String = "INSERT OR REPLACE INTO `XapiActivityEntity` (`actUid`,`actIdIri`,`actType`,`actMoreInfo`,`actInteractionType`,`actCorrectResponsePatterns`,`actNonSignificantLastModified`,`actSignificantLastModified`,`actStored`,`actFlags`,`actObjectTypeSet`) VALUES (?,?,?,?,?,?,?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiActivityEntity) {
        statement.bindLong(1, entity.actUid)
        statement.bindText(2, entity.actIdIri)
        val _tmpActType: String? = entity.actType
        if (_tmpActType == null) {
          statement.bindNull(3)
        } else {
          statement.bindText(3, _tmpActType)
        }
        val _tmpActMoreInfo: String? = entity.actMoreInfo
        if (_tmpActMoreInfo == null) {
          statement.bindNull(4)
        } else {
          statement.bindText(4, _tmpActMoreInfo)
        }
        val _tmpActInteractionType: XapiInteractionTypeEnum? = entity.actInteractionType
        val _tmp: Int?
        if (_tmpActInteractionType == null) {
          _tmp = null
        } else {
          _tmp = __schoolTypeConverters.fromXapiInteractionTypeEnum(_tmpActInteractionType)
        }
        if (_tmp == null) {
          statement.bindNull(5)
        } else {
          statement.bindLong(5, _tmp.toLong())
        }
        val _tmpActCorrectResponsePatterns: String? = entity.actCorrectResponsePatterns
        if (_tmpActCorrectResponsePatterns == null) {
          statement.bindNull(6)
        } else {
          statement.bindText(6, _tmpActCorrectResponsePatterns)
        }
        val _tmp_1: Long? = __sharedConverters.fromInstant(entity.actNonSignificantLastModified)
        if (_tmp_1 == null) {
          statement.bindNull(7)
        } else {
          statement.bindLong(7, _tmp_1)
        }
        val _tmp_2: Long? = __sharedConverters.fromInstant(entity.actSignificantLastModified)
        if (_tmp_2 == null) {
          statement.bindNull(8)
        } else {
          statement.bindLong(8, _tmp_2)
        }
        val _tmp_3: Long? = __sharedConverters.fromInstant(entity.actStored)
        if (_tmp_3 == null) {
          statement.bindNull(9)
        } else {
          statement.bindLong(9, _tmp_3)
        }
        statement.bindLong(10, entity.actFlags.toLong())
        val _tmp_4: Int = if (entity.actObjectTypeSet) 1 else 0
        statement.bindLong(11, _tmp_4.toLong())
      }
    }
  }

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

  public override suspend fun upsert(xapiActivityEntity: XapiActivityEntity): Unit = performSuspending(__db, false, true) { _connection ->
    __insertAdapterOfXapiActivityEntity_1.insert(_connection, xapiActivityEntity)
  }

  public override suspend fun findByUidList(activityUids: List<Long>): List<XapiActivityEntities> {
    val _stringBuilder: StringBuilder = StringBuilder()
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("        SELECT XapiActivityEntity.*")
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("          FROM XapiActivityEntity")
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("         WHERE XapiActivityEntity.actUid IN (")
    val _inputSize: Int = activityUids.size
    appendPlaceholders(_stringBuilder, _inputSize)
    _stringBuilder.append(")")
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("    ")
    val _sql: String = _stringBuilder.toString()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        for (_item: Long in activityUids) {
          _stmt.bindLong(_argIndex, _item)
          _argIndex++
        }
        val _columnIndexOfActUid: Int = getColumnIndexOrThrow(_stmt, "actUid")
        val _columnIndexOfActIdIri: Int = getColumnIndexOrThrow(_stmt, "actIdIri")
        val _columnIndexOfActType: Int = getColumnIndexOrThrow(_stmt, "actType")
        val _columnIndexOfActMoreInfo: Int = getColumnIndexOrThrow(_stmt, "actMoreInfo")
        val _columnIndexOfActInteractionType: Int = getColumnIndexOrThrow(_stmt, "actInteractionType")
        val _columnIndexOfActCorrectResponsePatterns: Int = getColumnIndexOrThrow(_stmt, "actCorrectResponsePatterns")
        val _columnIndexOfActNonSignificantLastModified: Int = getColumnIndexOrThrow(_stmt, "actNonSignificantLastModified")
        val _columnIndexOfActSignificantLastModified: Int = getColumnIndexOrThrow(_stmt, "actSignificantLastModified")
        val _columnIndexOfActStored: Int = getColumnIndexOrThrow(_stmt, "actStored")
        val _columnIndexOfActFlags: Int = getColumnIndexOrThrow(_stmt, "actFlags")
        val _columnIndexOfActObjectTypeSet: Int = getColumnIndexOrThrow(_stmt, "actObjectTypeSet")
        val _collectionActivityLangMapEntries: LongSparseArray<MutableList<XapiActivityLangMapEntry>> = LongSparseArray<MutableList<XapiActivityLangMapEntry>>()
        val _collectionActivityInteractionEntities: LongSparseArray<MutableList<XapiActivityInteractionEntity>> = LongSparseArray<MutableList<XapiActivityInteractionEntity>>()
        val _collectionActivityExtensionEntities: LongSparseArray<MutableList<XapiActivityExtensionEntity>> = LongSparseArray<MutableList<XapiActivityExtensionEntity>>()
        while (_stmt.step()) {
          val _tmpKey: Long
          _tmpKey = _stmt.getLong(_columnIndexOfActUid)
          if (!_collectionActivityLangMapEntries.containsKey(_tmpKey)) {
            _collectionActivityLangMapEntries.put(_tmpKey, mutableListOf())
          }
          val _tmpKey_1: Long
          _tmpKey_1 = _stmt.getLong(_columnIndexOfActUid)
          if (!_collectionActivityInteractionEntities.containsKey(_tmpKey_1)) {
            _collectionActivityInteractionEntities.put(_tmpKey_1, mutableListOf())
          }
          val _tmpKey_2: Long
          _tmpKey_2 = _stmt.getLong(_columnIndexOfActUid)
          if (!_collectionActivityExtensionEntities.containsKey(_tmpKey_2)) {
            _collectionActivityExtensionEntities.put(_tmpKey_2, mutableListOf())
          }
        }
        _stmt.reset()
        __fetchRelationshipXapiActivityLangMapEntryAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityLangMapEntry(_connection, _collectionActivityLangMapEntries)
        __fetchRelationshipXapiActivityInteractionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityInteractionEntity(_connection, _collectionActivityInteractionEntities)
        __fetchRelationshipXapiActivityExtensionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityExtensionEntity(_connection, _collectionActivityExtensionEntities)
        val _result: MutableList<XapiActivityEntities> = mutableListOf()
        while (_stmt.step()) {
          val _item_1: XapiActivityEntities
          val _tmpActivityEntity: XapiActivityEntity
          val _tmpActUid: Long
          _tmpActUid = _stmt.getLong(_columnIndexOfActUid)
          val _tmpActIdIri: String
          _tmpActIdIri = _stmt.getText(_columnIndexOfActIdIri)
          val _tmpActType: String?
          if (_stmt.isNull(_columnIndexOfActType)) {
            _tmpActType = null
          } else {
            _tmpActType = _stmt.getText(_columnIndexOfActType)
          }
          val _tmpActMoreInfo: String?
          if (_stmt.isNull(_columnIndexOfActMoreInfo)) {
            _tmpActMoreInfo = null
          } else {
            _tmpActMoreInfo = _stmt.getText(_columnIndexOfActMoreInfo)
          }
          val _tmpActInteractionType: XapiInteractionTypeEnum?
          val _tmp: Int?
          if (_stmt.isNull(_columnIndexOfActInteractionType)) {
            _tmp = null
          } else {
            _tmp = _stmt.getLong(_columnIndexOfActInteractionType).toInt()
          }
          if (_tmp == null) {
            _tmpActInteractionType = null
          } else {
            _tmpActInteractionType = __schoolTypeConverters.toXapiInteractionTypeEnum(_tmp)
          }
          val _tmpActCorrectResponsePatterns: String?
          if (_stmt.isNull(_columnIndexOfActCorrectResponsePatterns)) {
            _tmpActCorrectResponsePatterns = null
          } else {
            _tmpActCorrectResponsePatterns = _stmt.getText(_columnIndexOfActCorrectResponsePatterns)
          }
          val _tmpActNonSignificantLastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfActNonSignificantLastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfActNonSignificantLastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActNonSignificantLastModified = _tmp_2
          }
          val _tmpActSignificantLastModified: Instant
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfActSignificantLastModified)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfActSignificantLastModified)
          }
          val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
          if (_tmp_4 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActSignificantLastModified = _tmp_4
          }
          val _tmpActStored: Instant
          val _tmp_5: Long?
          if (_stmt.isNull(_columnIndexOfActStored)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getLong(_columnIndexOfActStored)
          }
          val _tmp_6: Instant? = __sharedConverters.toInstant(_tmp_5)
          if (_tmp_6 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActStored = _tmp_6
          }
          val _tmpActFlags: Int
          _tmpActFlags = _stmt.getLong(_columnIndexOfActFlags).toInt()
          val _tmpActObjectTypeSet: Boolean
          val _tmp_7: Int
          _tmp_7 = _stmt.getLong(_columnIndexOfActObjectTypeSet).toInt()
          _tmpActObjectTypeSet = _tmp_7 != 0
          _tmpActivityEntity = XapiActivityEntity(_tmpActUid,_tmpActIdIri,_tmpActType,_tmpActMoreInfo,_tmpActInteractionType,_tmpActCorrectResponsePatterns,_tmpActNonSignificantLastModified,_tmpActSignificantLastModified,_tmpActStored,_tmpActFlags,_tmpActObjectTypeSet)
          val _tmpActivityLangMapEntriesCollection: MutableList<XapiActivityLangMapEntry>
          val _tmpKey_3: Long
          _tmpKey_3 = _stmt.getLong(_columnIndexOfActUid)
          _tmpActivityLangMapEntriesCollection = checkNotNull(_collectionActivityLangMapEntries.get(_tmpKey_3))
          val _tmpActivityInteractionEntitiesCollection: MutableList<XapiActivityInteractionEntity>
          val _tmpKey_4: Long
          _tmpKey_4 = _stmt.getLong(_columnIndexOfActUid)
          _tmpActivityInteractionEntitiesCollection = checkNotNull(_collectionActivityInteractionEntities.get(_tmpKey_4))
          val _tmpActivityExtensionEntitiesCollection: MutableList<XapiActivityExtensionEntity>
          val _tmpKey_5: Long
          _tmpKey_5 = _stmt.getLong(_columnIndexOfActUid)
          _tmpActivityExtensionEntitiesCollection = checkNotNull(_collectionActivityExtensionEntities.get(_tmpKey_5))
          _item_1 = XapiActivityEntities(_tmpActivityEntity,_tmpActivityLangMapEntriesCollection,_tmpActivityInteractionEntitiesCollection,_tmpActivityExtensionEntitiesCollection)
          _result.add(_item_1)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun findByUidAsync(activityUid: Long): XapiActivityEntity? {
    val _sql: String = """
        |
        |        SELECT XapiActivityEntity.*
        |          FROM XapiActivityEntity
        |         WHERE XapiActivityEntity.actUid = ? 
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, activityUid)
        val _columnIndexOfActUid: Int = getColumnIndexOrThrow(_stmt, "actUid")
        val _columnIndexOfActIdIri: Int = getColumnIndexOrThrow(_stmt, "actIdIri")
        val _columnIndexOfActType: Int = getColumnIndexOrThrow(_stmt, "actType")
        val _columnIndexOfActMoreInfo: Int = getColumnIndexOrThrow(_stmt, "actMoreInfo")
        val _columnIndexOfActInteractionType: Int = getColumnIndexOrThrow(_stmt, "actInteractionType")
        val _columnIndexOfActCorrectResponsePatterns: Int = getColumnIndexOrThrow(_stmt, "actCorrectResponsePatterns")
        val _columnIndexOfActNonSignificantLastModified: Int = getColumnIndexOrThrow(_stmt, "actNonSignificantLastModified")
        val _columnIndexOfActSignificantLastModified: Int = getColumnIndexOrThrow(_stmt, "actSignificantLastModified")
        val _columnIndexOfActStored: Int = getColumnIndexOrThrow(_stmt, "actStored")
        val _columnIndexOfActFlags: Int = getColumnIndexOrThrow(_stmt, "actFlags")
        val _columnIndexOfActObjectTypeSet: Int = getColumnIndexOrThrow(_stmt, "actObjectTypeSet")
        val _result: XapiActivityEntity?
        if (_stmt.step()) {
          val _tmpActUid: Long
          _tmpActUid = _stmt.getLong(_columnIndexOfActUid)
          val _tmpActIdIri: String
          _tmpActIdIri = _stmt.getText(_columnIndexOfActIdIri)
          val _tmpActType: String?
          if (_stmt.isNull(_columnIndexOfActType)) {
            _tmpActType = null
          } else {
            _tmpActType = _stmt.getText(_columnIndexOfActType)
          }
          val _tmpActMoreInfo: String?
          if (_stmt.isNull(_columnIndexOfActMoreInfo)) {
            _tmpActMoreInfo = null
          } else {
            _tmpActMoreInfo = _stmt.getText(_columnIndexOfActMoreInfo)
          }
          val _tmpActInteractionType: XapiInteractionTypeEnum?
          val _tmp: Int?
          if (_stmt.isNull(_columnIndexOfActInteractionType)) {
            _tmp = null
          } else {
            _tmp = _stmt.getLong(_columnIndexOfActInteractionType).toInt()
          }
          if (_tmp == null) {
            _tmpActInteractionType = null
          } else {
            _tmpActInteractionType = __schoolTypeConverters.toXapiInteractionTypeEnum(_tmp)
          }
          val _tmpActCorrectResponsePatterns: String?
          if (_stmt.isNull(_columnIndexOfActCorrectResponsePatterns)) {
            _tmpActCorrectResponsePatterns = null
          } else {
            _tmpActCorrectResponsePatterns = _stmt.getText(_columnIndexOfActCorrectResponsePatterns)
          }
          val _tmpActNonSignificantLastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfActNonSignificantLastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfActNonSignificantLastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActNonSignificantLastModified = _tmp_2
          }
          val _tmpActSignificantLastModified: Instant
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfActSignificantLastModified)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfActSignificantLastModified)
          }
          val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
          if (_tmp_4 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActSignificantLastModified = _tmp_4
          }
          val _tmpActStored: Instant
          val _tmp_5: Long?
          if (_stmt.isNull(_columnIndexOfActStored)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getLong(_columnIndexOfActStored)
          }
          val _tmp_6: Instant? = __sharedConverters.toInstant(_tmp_5)
          if (_tmp_6 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActStored = _tmp_6
          }
          val _tmpActFlags: Int
          _tmpActFlags = _stmt.getLong(_columnIndexOfActFlags).toInt()
          val _tmpActObjectTypeSet: Boolean
          val _tmp_7: Int
          _tmp_7 = _stmt.getLong(_columnIndexOfActObjectTypeSet).toInt()
          _tmpActObjectTypeSet = _tmp_7 != 0
          _result = XapiActivityEntity(_tmpActUid,_tmpActIdIri,_tmpActType,_tmpActMoreInfo,_tmpActInteractionType,_tmpActCorrectResponsePatterns,_tmpActNonSignificantLastModified,_tmpActSignificantLastModified,_tmpActStored,_tmpActFlags,_tmpActObjectTypeSet)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun getEntitiesByUid(activityUid: Long): XapiActivityEntities? {
    val _sql: String = """
        |
        |        SELECT XapiActivityEntity.*
        |          FROM XapiActivityEntity
        |         WHERE XapiActivityEntity.actUid = ? 
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, activityUid)
        val _columnIndexOfActUid: Int = getColumnIndexOrThrow(_stmt, "actUid")
        val _columnIndexOfActIdIri: Int = getColumnIndexOrThrow(_stmt, "actIdIri")
        val _columnIndexOfActType: Int = getColumnIndexOrThrow(_stmt, "actType")
        val _columnIndexOfActMoreInfo: Int = getColumnIndexOrThrow(_stmt, "actMoreInfo")
        val _columnIndexOfActInteractionType: Int = getColumnIndexOrThrow(_stmt, "actInteractionType")
        val _columnIndexOfActCorrectResponsePatterns: Int = getColumnIndexOrThrow(_stmt, "actCorrectResponsePatterns")
        val _columnIndexOfActNonSignificantLastModified: Int = getColumnIndexOrThrow(_stmt, "actNonSignificantLastModified")
        val _columnIndexOfActSignificantLastModified: Int = getColumnIndexOrThrow(_stmt, "actSignificantLastModified")
        val _columnIndexOfActStored: Int = getColumnIndexOrThrow(_stmt, "actStored")
        val _columnIndexOfActFlags: Int = getColumnIndexOrThrow(_stmt, "actFlags")
        val _columnIndexOfActObjectTypeSet: Int = getColumnIndexOrThrow(_stmt, "actObjectTypeSet")
        val _collectionActivityLangMapEntries: LongSparseArray<MutableList<XapiActivityLangMapEntry>> = LongSparseArray<MutableList<XapiActivityLangMapEntry>>()
        val _collectionActivityInteractionEntities: LongSparseArray<MutableList<XapiActivityInteractionEntity>> = LongSparseArray<MutableList<XapiActivityInteractionEntity>>()
        val _collectionActivityExtensionEntities: LongSparseArray<MutableList<XapiActivityExtensionEntity>> = LongSparseArray<MutableList<XapiActivityExtensionEntity>>()
        while (_stmt.step()) {
          val _tmpKey: Long
          _tmpKey = _stmt.getLong(_columnIndexOfActUid)
          if (!_collectionActivityLangMapEntries.containsKey(_tmpKey)) {
            _collectionActivityLangMapEntries.put(_tmpKey, mutableListOf())
          }
          val _tmpKey_1: Long
          _tmpKey_1 = _stmt.getLong(_columnIndexOfActUid)
          if (!_collectionActivityInteractionEntities.containsKey(_tmpKey_1)) {
            _collectionActivityInteractionEntities.put(_tmpKey_1, mutableListOf())
          }
          val _tmpKey_2: Long
          _tmpKey_2 = _stmt.getLong(_columnIndexOfActUid)
          if (!_collectionActivityExtensionEntities.containsKey(_tmpKey_2)) {
            _collectionActivityExtensionEntities.put(_tmpKey_2, mutableListOf())
          }
        }
        _stmt.reset()
        __fetchRelationshipXapiActivityLangMapEntryAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityLangMapEntry(_connection, _collectionActivityLangMapEntries)
        __fetchRelationshipXapiActivityInteractionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityInteractionEntity(_connection, _collectionActivityInteractionEntities)
        __fetchRelationshipXapiActivityExtensionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityExtensionEntity(_connection, _collectionActivityExtensionEntities)
        val _result: XapiActivityEntities?
        if (_stmt.step()) {
          val _tmpActivityEntity: XapiActivityEntity
          val _tmpActUid: Long
          _tmpActUid = _stmt.getLong(_columnIndexOfActUid)
          val _tmpActIdIri: String
          _tmpActIdIri = _stmt.getText(_columnIndexOfActIdIri)
          val _tmpActType: String?
          if (_stmt.isNull(_columnIndexOfActType)) {
            _tmpActType = null
          } else {
            _tmpActType = _stmt.getText(_columnIndexOfActType)
          }
          val _tmpActMoreInfo: String?
          if (_stmt.isNull(_columnIndexOfActMoreInfo)) {
            _tmpActMoreInfo = null
          } else {
            _tmpActMoreInfo = _stmt.getText(_columnIndexOfActMoreInfo)
          }
          val _tmpActInteractionType: XapiInteractionTypeEnum?
          val _tmp: Int?
          if (_stmt.isNull(_columnIndexOfActInteractionType)) {
            _tmp = null
          } else {
            _tmp = _stmt.getLong(_columnIndexOfActInteractionType).toInt()
          }
          if (_tmp == null) {
            _tmpActInteractionType = null
          } else {
            _tmpActInteractionType = __schoolTypeConverters.toXapiInteractionTypeEnum(_tmp)
          }
          val _tmpActCorrectResponsePatterns: String?
          if (_stmt.isNull(_columnIndexOfActCorrectResponsePatterns)) {
            _tmpActCorrectResponsePatterns = null
          } else {
            _tmpActCorrectResponsePatterns = _stmt.getText(_columnIndexOfActCorrectResponsePatterns)
          }
          val _tmpActNonSignificantLastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfActNonSignificantLastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfActNonSignificantLastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActNonSignificantLastModified = _tmp_2
          }
          val _tmpActSignificantLastModified: Instant
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfActSignificantLastModified)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfActSignificantLastModified)
          }
          val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
          if (_tmp_4 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActSignificantLastModified = _tmp_4
          }
          val _tmpActStored: Instant
          val _tmp_5: Long?
          if (_stmt.isNull(_columnIndexOfActStored)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getLong(_columnIndexOfActStored)
          }
          val _tmp_6: Instant? = __sharedConverters.toInstant(_tmp_5)
          if (_tmp_6 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpActStored = _tmp_6
          }
          val _tmpActFlags: Int
          _tmpActFlags = _stmt.getLong(_columnIndexOfActFlags).toInt()
          val _tmpActObjectTypeSet: Boolean
          val _tmp_7: Int
          _tmp_7 = _stmt.getLong(_columnIndexOfActObjectTypeSet).toInt()
          _tmpActObjectTypeSet = _tmp_7 != 0
          _tmpActivityEntity = XapiActivityEntity(_tmpActUid,_tmpActIdIri,_tmpActType,_tmpActMoreInfo,_tmpActInteractionType,_tmpActCorrectResponsePatterns,_tmpActNonSignificantLastModified,_tmpActSignificantLastModified,_tmpActStored,_tmpActFlags,_tmpActObjectTypeSet)
          val _tmpActivityLangMapEntriesCollection: MutableList<XapiActivityLangMapEntry>
          val _tmpKey_3: Long
          _tmpKey_3 = _stmt.getLong(_columnIndexOfActUid)
          _tmpActivityLangMapEntriesCollection = checkNotNull(_collectionActivityLangMapEntries.get(_tmpKey_3))
          val _tmpActivityInteractionEntitiesCollection: MutableList<XapiActivityInteractionEntity>
          val _tmpKey_4: Long
          _tmpKey_4 = _stmt.getLong(_columnIndexOfActUid)
          _tmpActivityInteractionEntitiesCollection = checkNotNull(_collectionActivityInteractionEntities.get(_tmpKey_4))
          val _tmpActivityExtensionEntitiesCollection: MutableList<XapiActivityExtensionEntity>
          val _tmpKey_5: Long
          _tmpKey_5 = _stmt.getLong(_columnIndexOfActUid)
          _tmpActivityExtensionEntitiesCollection = checkNotNull(_collectionActivityExtensionEntities.get(_tmpKey_5))
          _result = XapiActivityEntities(_tmpActivityEntity,_tmpActivityLangMapEntriesCollection,_tmpActivityInteractionEntitiesCollection,_tmpActivityExtensionEntitiesCollection)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun updateIfMoreInfoChanged(
    activityUid: Long,
    actMoreInfo: String?,
    actLct: Long,
  ) {
    val _sql: String = """
        |
        |        UPDATE XapiActivityEntity
        |           SET actMoreInfo = ?,
        |               actNonSignificantLastModified = ?
        |        WHERE actUid = ?
        |          AND actMoreInfo != ?      
        |    
        """.trimMargin()
    return performSuspending(__db, false, true) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        if (actMoreInfo == null) {
          _stmt.bindNull(_argIndex)
        } else {
          _stmt.bindText(_argIndex, actMoreInfo)
        }
        _argIndex = 2
        _stmt.bindLong(_argIndex, actLct)
        _argIndex = 3
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 4
        if (actMoreInfo == null) {
          _stmt.bindNull(_argIndex)
        } else {
          _stmt.bindText(_argIndex, actMoreInfo)
        }
        _stmt.step()
      } finally {
        _stmt.close()
      }
    }
  }

  private fun __fetchRelationshipXapiActivityLangMapEntryAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityLangMapEntry(_connection: SQLiteConnection, _map: LongSparseArray<MutableList<XapiActivityLangMapEntry>>) {
    if (_map.isEmpty()) {
      return
    }
    if (_map.size() > 999) {
      recursiveFetchLongSparseArray(_map, true) { _tmpMap ->
        __fetchRelationshipXapiActivityLangMapEntryAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityLangMapEntry(_connection, _tmpMap)
      }
      return
    }
    val _stringBuilder: StringBuilder = StringBuilder()
    _stringBuilder.append("SELECT `almeActivityUid`,`almeKeyHash`,`almeProperty`,`almeInteractionId`,`almeLangCode`,`almeValue`,`almeLastModified` FROM `XapiActivityLangMapEntry` WHERE `almeActivityUid` IN (")
    val _inputSize: Int = _map.size()
    appendPlaceholders(_stringBuilder, _inputSize)
    _stringBuilder.append(")")
    val _sql: String = _stringBuilder.toString()
    val _stmt: SQLiteStatement = _connection.prepare(_sql)
    var _argIndex: Int = 1
    for (i in 0 until _map.size()) {
      val _item: Long = _map.keyAt(i)
      _stmt.bindLong(_argIndex, _item)
      _argIndex++
    }
    try {
      val _itemKeyIndex: Int = getColumnIndex(_stmt, "almeActivityUid")
      if (_itemKeyIndex == -1) {
        return
      }
      val _columnIndexOfAlmeActivityUid: Int = 0
      val _columnIndexOfAlmeKeyHash: Int = 1
      val _columnIndexOfAlmeProperty: Int = 2
      val _columnIndexOfAlmeInteractionId: Int = 3
      val _columnIndexOfAlmeLangCode: Int = 4
      val _columnIndexOfAlmeValue: Int = 5
      val _columnIndexOfAlmeLastModified: Int = 6
      while (_stmt.step()) {
        val _tmpKey: Long
        _tmpKey = _stmt.getLong(_itemKeyIndex)
        val _tmpRelation: MutableList<XapiActivityLangMapEntry>? = _map.get(_tmpKey)
        if (_tmpRelation != null) {
          val _item_1: XapiActivityLangMapEntry
          val _tmpAlmeActivityUid: Long
          _tmpAlmeActivityUid = _stmt.getLong(_columnIndexOfAlmeActivityUid)
          val _tmpAlmeKeyHash: Long
          _tmpAlmeKeyHash = _stmt.getLong(_columnIndexOfAlmeKeyHash)
          val _tmpAlmeProperty: XapiActivityLangMapEntryPropEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfAlmeProperty).toInt()
          _tmpAlmeProperty = __schoolTypeConverters.toActivityLangMapEntryPropEnum(_tmp)
          val _tmpAlmeInteractionId: String?
          if (_stmt.isNull(_columnIndexOfAlmeInteractionId)) {
            _tmpAlmeInteractionId = null
          } else {
            _tmpAlmeInteractionId = _stmt.getText(_columnIndexOfAlmeInteractionId)
          }
          val _tmpAlmeLangCode: String
          _tmpAlmeLangCode = _stmt.getText(_columnIndexOfAlmeLangCode)
          val _tmpAlmeValue: String
          _tmpAlmeValue = _stmt.getText(_columnIndexOfAlmeValue)
          val _tmpAlmeLastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfAlmeLastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfAlmeLastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpAlmeLastModified = _tmp_2
          }
          _item_1 = XapiActivityLangMapEntry(_tmpAlmeActivityUid,_tmpAlmeKeyHash,_tmpAlmeProperty,_tmpAlmeInteractionId,_tmpAlmeLangCode,_tmpAlmeValue,_tmpAlmeLastModified)
          _tmpRelation.add(_item_1)
        }
      }
    } finally {
      _stmt.close()
    }
  }

  private fun __fetchRelationshipXapiActivityInteractionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityInteractionEntity(_connection: SQLiteConnection, _map: LongSparseArray<MutableList<XapiActivityInteractionEntity>>) {
    if (_map.isEmpty()) {
      return
    }
    if (_map.size() > 999) {
      recursiveFetchLongSparseArray(_map, true) { _tmpMap ->
        __fetchRelationshipXapiActivityInteractionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityInteractionEntity(_connection, _tmpMap)
      }
      return
    }
    val _stringBuilder: StringBuilder = StringBuilder()
    _stringBuilder.append("SELECT `aieUid`,`aieActivityUid`,`aieProp`,`aieId` FROM `XapiActivityInteractionEntity` WHERE `aieActivityUid` IN (")
    val _inputSize: Int = _map.size()
    appendPlaceholders(_stringBuilder, _inputSize)
    _stringBuilder.append(")")
    val _sql: String = _stringBuilder.toString()
    val _stmt: SQLiteStatement = _connection.prepare(_sql)
    var _argIndex: Int = 1
    for (i in 0 until _map.size()) {
      val _item: Long = _map.keyAt(i)
      _stmt.bindLong(_argIndex, _item)
      _argIndex++
    }
    try {
      val _itemKeyIndex: Int = getColumnIndex(_stmt, "aieActivityUid")
      if (_itemKeyIndex == -1) {
        return
      }
      val _columnIndexOfAieUid: Int = 0
      val _columnIndexOfAieActivityUid: Int = 1
      val _columnIndexOfAieProp: Int = 2
      val _columnIndexOfAieId: Int = 3
      while (_stmt.step()) {
        val _tmpKey: Long
        _tmpKey = _stmt.getLong(_itemKeyIndex)
        val _tmpRelation: MutableList<XapiActivityInteractionEntity>? = _map.get(_tmpKey)
        if (_tmpRelation != null) {
          val _item_1: 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_1 = XapiActivityInteractionEntity(_tmpAieUid,_tmpAieActivityUid,_tmpAieProp,_tmpAieId)
          _tmpRelation.add(_item_1)
        }
      }
    } finally {
      _stmt.close()
    }
  }

  private fun __fetchRelationshipXapiActivityExtensionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityExtensionEntity(_connection: SQLiteConnection, _map: LongSparseArray<MutableList<XapiActivityExtensionEntity>>) {
    if (_map.isEmpty()) {
      return
    }
    if (_map.size() > 999) {
      recursiveFetchLongSparseArray(_map, true) { _tmpMap ->
        __fetchRelationshipXapiActivityExtensionEntityAsworldRespectDatalayerDbSchoolXapiEntitiesXapiActivityExtensionEntity(_connection, _tmpMap)
      }
      return
    }
    val _stringBuilder: StringBuilder = StringBuilder()
    _stringBuilder.append("SELECT `aeeActivityUid`,`aeeKeyHash`,`aeeKey`,`aeeJson`,`aeeLastMod` FROM `XapiActivityExtensionEntity` WHERE `aeeActivityUid` IN (")
    val _inputSize: Int = _map.size()
    appendPlaceholders(_stringBuilder, _inputSize)
    _stringBuilder.append(")")
    val _sql: String = _stringBuilder.toString()
    val _stmt: SQLiteStatement = _connection.prepare(_sql)
    var _argIndex: Int = 1
    for (i in 0 until _map.size()) {
      val _item: Long = _map.keyAt(i)
      _stmt.bindLong(_argIndex, _item)
      _argIndex++
    }
    try {
      val _itemKeyIndex: Int = getColumnIndex(_stmt, "aeeActivityUid")
      if (_itemKeyIndex == -1) {
        return
      }
      val _columnIndexOfAeeActivityUid: Int = 0
      val _columnIndexOfAeeKeyHash: Int = 1
      val _columnIndexOfAeeKey: Int = 2
      val _columnIndexOfAeeJson: Int = 3
      val _columnIndexOfAeeLastMod: Int = 4
      while (_stmt.step()) {
        val _tmpKey: Long
        _tmpKey = _stmt.getLong(_itemKeyIndex)
        val _tmpRelation: MutableList<XapiActivityExtensionEntity>? = _map.get(_tmpKey)
        if (_tmpRelation != null) {
          val _item_1: 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)
          _item_1 = XapiActivityExtensionEntity(_tmpAeeActivityUid,_tmpAeeKeyHash,_tmpAeeKey,_tmpAeeJson,_tmpAeeLastMod)
          _tmpRelation.add(_item_1)
        }
      }
    } finally {
      _stmt.close()
    }
  }

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