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

import androidx.room.EntityInsertAdapter
import androidx.room.RoomDatabase
import androidx.room.RoomRawQuery
import androidx.room.coroutines.createFlow
import androidx.room.util.getColumnIndex
import androidx.room.util.getColumnIndexOrThrow
import androidx.room.util.performSuspending
import androidx.sqlite.SQLiteStatement
import javax.`annotation`.processing.Generated
import kotlin.Boolean
import kotlin.Double
import kotlin.Float
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.time.Instant
import kotlinx.coroutines.flow.Flow
import world.respect.datalayer.db.school.SchoolTypeConverters
import world.respect.datalayer.db.school.xapi.composites.XapiStatementAndJsonEntities
import world.respect.datalayer.db.school.xapi.composites.XapiSubstatementAndVerbEntity
import world.respect.datalayer.db.school.xapi.composites.XapiTimes
import world.respect.datalayer.db.school.xapi.entities.XapiAssignmentProgressEntityRow
import world.respect.datalayer.db.school.xapi.entities.XapiAssignmentSummaryEntityRow
import world.respect.datalayer.db.school.xapi.entities.XapiStatementEntity
import world.respect.datalayer.db.school.xapi.entities.XapiStatementEntityObjectTypeEnum
import world.respect.datalayer.db.school.xapi.entities.XapiVerbEntity
import world.respect.datalayer.db.shared.SharedConverters
import world.respect.datalayer.school.model.StatusEnum
import world.respect.datalayer.school.model.report.StatementReportRow

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

  private val __insertAdapterOfXapiStatementEntity: EntityInsertAdapter<XapiStatementEntity>

  private val __schoolTypeConverters: SchoolTypeConverters = SchoolTypeConverters()

  private val __sharedConverters: SharedConverters = SharedConverters()
  init {
    this.__db = __db
    this.__insertAdapterOfXapiStatementEntity = object : EntityInsertAdapter<XapiStatementEntity>() {
      protected override fun createQuery(): String = "INSERT OR IGNORE INTO `XapiStatementEntity` (`statementIdHi`,`statementIdLo`,`statementVerbUid`,`statementVerbId`,`statementObjectType`,`statementObjectActivityId`,`statementObjectUid1`,`statementObjectUid2`,`statementActorUid`,`authorityActorUid`,`resultCompletion`,`resultSuccess`,`resultScoreScaled`,`resultScoreRaw`,`resultScoreMin`,`resultScoreMax`,`resultDuration`,`resultResponse`,`resultExtensions`,`timestamp`,`stored`,`contextRegistrationHi`,`contextRegistrationLo`,`contextRegistrationHash`,`contextLanguage`,`contextPlatform`,`contextRevision`,`contextStatementRefIdHi`,`contextStatementRefIdLo`,`contextInstructorActorUid`,`contextTeamActorUid`,`extensionProgress`,`completionOrProgress`,`isSubStatement`,`statementVersion`,`stmtVoid`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiStatementEntity) {
        statement.bindLong(1, entity.statementIdHi)
        statement.bindLong(2, entity.statementIdLo)
        statement.bindLong(3, entity.statementVerbUid)
        statement.bindText(4, entity.statementVerbId)
        val _tmp: Int = __schoolTypeConverters.fromStatementEntityObjectTypeEnum(entity.statementObjectType)
        statement.bindLong(5, _tmp.toLong())
        val _tmpStatementObjectActivityId: String? = entity.statementObjectActivityId
        if (_tmpStatementObjectActivityId == null) {
          statement.bindNull(6)
        } else {
          statement.bindText(6, _tmpStatementObjectActivityId)
        }
        statement.bindLong(7, entity.statementObjectUid1)
        statement.bindLong(8, entity.statementObjectUid2)
        statement.bindLong(9, entity.statementActorUid)
        statement.bindLong(10, entity.authorityActorUid)
        val _tmpResultCompletion: Boolean? = entity.resultCompletion
        val _tmp_1: Int? = _tmpResultCompletion?.let { if (it) 1 else 0 }
        if (_tmp_1 == null) {
          statement.bindNull(11)
        } else {
          statement.bindLong(11, _tmp_1.toLong())
        }
        val _tmpResultSuccess: Boolean? = entity.resultSuccess
        val _tmp_2: Int? = _tmpResultSuccess?.let { if (it) 1 else 0 }
        if (_tmp_2 == null) {
          statement.bindNull(12)
        } else {
          statement.bindLong(12, _tmp_2.toLong())
        }
        val _tmpResultScoreScaled: Float? = entity.resultScoreScaled
        if (_tmpResultScoreScaled == null) {
          statement.bindNull(13)
        } else {
          statement.bindDouble(13, _tmpResultScoreScaled.toDouble())
        }
        val _tmpResultScoreRaw: Float? = entity.resultScoreRaw
        if (_tmpResultScoreRaw == null) {
          statement.bindNull(14)
        } else {
          statement.bindDouble(14, _tmpResultScoreRaw.toDouble())
        }
        val _tmpResultScoreMin: Float? = entity.resultScoreMin
        if (_tmpResultScoreMin == null) {
          statement.bindNull(15)
        } else {
          statement.bindDouble(15, _tmpResultScoreMin.toDouble())
        }
        val _tmpResultScoreMax: Float? = entity.resultScoreMax
        if (_tmpResultScoreMax == null) {
          statement.bindNull(16)
        } else {
          statement.bindDouble(16, _tmpResultScoreMax.toDouble())
        }
        val _tmpResultDuration: Long? = entity.resultDuration
        if (_tmpResultDuration == null) {
          statement.bindNull(17)
        } else {
          statement.bindLong(17, _tmpResultDuration)
        }
        val _tmpResultResponse: String? = entity.resultResponse
        if (_tmpResultResponse == null) {
          statement.bindNull(18)
        } else {
          statement.bindText(18, _tmpResultResponse)
        }
        val _tmpResultExtensions: String? = entity.resultExtensions
        if (_tmpResultExtensions == null) {
          statement.bindNull(19)
        } else {
          statement.bindText(19, _tmpResultExtensions)
        }
        val _tmpTimestamp: Instant? = entity.timestamp
        val _tmp_3: Long? = __sharedConverters.fromInstant(_tmpTimestamp)
        if (_tmp_3 == null) {
          statement.bindNull(20)
        } else {
          statement.bindLong(20, _tmp_3)
        }
        val _tmpStored: Instant? = entity.stored
        val _tmp_4: Long? = __sharedConverters.fromInstant(_tmpStored)
        if (_tmp_4 == null) {
          statement.bindNull(21)
        } else {
          statement.bindLong(21, _tmp_4)
        }
        statement.bindLong(22, entity.contextRegistrationHi)
        statement.bindLong(23, entity.contextRegistrationLo)
        statement.bindLong(24, entity.contextRegistrationHash)
        val _tmpContextLanguage: String? = entity.contextLanguage
        if (_tmpContextLanguage == null) {
          statement.bindNull(25)
        } else {
          statement.bindText(25, _tmpContextLanguage)
        }
        val _tmpContextPlatform: String? = entity.contextPlatform
        if (_tmpContextPlatform == null) {
          statement.bindNull(26)
        } else {
          statement.bindText(26, _tmpContextPlatform)
        }
        val _tmpContextRevision: String? = entity.contextRevision
        if (_tmpContextRevision == null) {
          statement.bindNull(27)
        } else {
          statement.bindText(27, _tmpContextRevision)
        }
        statement.bindLong(28, entity.contextStatementRefIdHi)
        statement.bindLong(29, entity.contextStatementRefIdLo)
        statement.bindLong(30, entity.contextInstructorActorUid)
        statement.bindLong(31, entity.contextTeamActorUid)
        val _tmpExtensionProgress: Int? = entity.extensionProgress
        if (_tmpExtensionProgress == null) {
          statement.bindNull(32)
        } else {
          statement.bindLong(32, _tmpExtensionProgress.toLong())
        }
        val _tmp_5: Int = if (entity.completionOrProgress) 1 else 0
        statement.bindLong(33, _tmp_5.toLong())
        val _tmp_6: Int = if (entity.isSubStatement) 1 else 0
        statement.bindLong(34, _tmp_6.toLong())
        val _tmpStatementVersion: String? = entity.statementVersion
        if (_tmpStatementVersion == null) {
          statement.bindNull(35)
        } else {
          statement.bindText(35, _tmpStatementVersion)
        }
        val _tmp_7: Int = if (entity.stmtVoid) 1 else 0
        statement.bindLong(36, _tmp_7.toLong())
      }
    }
  }

  public override suspend fun insertOrIgnoreListAsync(entityList: List<XapiStatementEntity>): Unit = performSuspending(__db, false, true) { _connection ->
    __insertAdapterOfXapiStatementEntity.insert(_connection, entityList)
  }

  public override suspend fun list(
    statementIdHi: Long,
    statementIdLo: Long,
    voidedStatementIdHi: Long,
    voidedStatementIdLo: Long,
    agentUid: Long,
    verbUid: Long,
    activityUid: Long,
    relatedAgents: Boolean,
    relatedActivities: Boolean,
    since: Long,
    until: Long,
    ascending: Boolean,
    limit: Int,
  ): List<XapiStatementAndJsonEntities> {
    val _sql: String = """
        |
        |            
        |            -- Get a list of all the actors that should be considered as related to agent parameter
        |            -- Eg the actor uid itself and any group members
        |          WITH AgentActorUids(uid) AS
        |               (SELECT ? AS uid
        |                 UNION
        |                SELECT XapiGroupMemberActorJoin.gmajGroupActorUid AS uid
        |                  FROM XapiGroupMemberActorJoin
        |                 WHERE ? != 0 
        |                   AND XapiGroupMemberActorJoin.gmajMemberActorUid = ?)
        |            
        |            
        |        SELECT XapiStatementEntity.*, XapiVerbEntity.*
        |          FROM XapiStatementEntity
        |               JOIN XapiVerbEntity
        |                    ON (    XapiVerbEntity.verbUid = XapiStatementEntity.statementVerbUid)
        |               LEFT JOIN XapiStatementEntity AS SubStatementEntity
        |                    ON (    XapiStatementEntity.statementObjectType = 4
        |                        AND SubStatementEntity.statementIdHi = XapiStatementEntity.statementObjectUid1
        |                        AND SubStatementEntity.statementIdLo = XapiStatementEntity.statementObjectUid2)
        |         WHERE (   (? = 0 AND ? = 0) 
        |                OR (     XapiStatementEntity.statementIdHi = ? 
        |                     AND XapiStatementEntity.statementIdLo = ?))
        |           AND (   (? = 0 AND ? = 0)
        |                OR (     XapiStatementEntity.statementIdHi = ? 
        |                     AND XapiStatementEntity.statementIdLo = ?
        |                     AND XapiStatementEntity.stmtVoid))
        |           AND (? = -9223372036854775808 OR XapiStatementEntity.stored > ?)
        |           AND (? = 9223372036854775807 OR XapiStatementEntity.stored <= ?)
        |           -- Handle agent parameter
        |           AND (    ? = 0 
        |                  OR (    XapiStatementEntity.statementActorUid IN 
        |                          (SELECT uid FROM AgentActorUids))
        |                  OR (    (    XapiStatementEntity.statementObjectType = 1
        |                            OR XapiStatementEntity.statementObjectType = 2)
        |                      AND (XapiStatementEntity.statementObjectUid1 IN (SELECT uid FROM AgentActorUids)))
        |                  -- Handle related agents        
        |                  OR (    ? 
        |                      AND (    XapiStatementEntity.authorityActorUid IN (SELECT uid FROM AgentActorUids)
        |                            OR XapiStatementEntity.contextTeamActorUid IN (SELECT uid FROM AgentActorUids)
        |                            OR XapiStatementEntity.contextInstructorActorUid IN (SELECT uid FROM AgentActorUids)
        |                            -- check substatement if applicable
        |                            OR (     SubStatementEntity.statementActorUid IS NOT NULL
        |                                AND (    SubStatementEntity.statementActorUid IN (SELECT uid FROM AgentActorUids)
        |                                      OR (     (   SubStatementEntity.statementObjectType = 1
        |                                                OR SubStatementEntity.statementObjectType = 2)
        |                                           AND (SubStatementEntity.statementObjectUid1 IN (SELECT uid FROM AgentActorUids)))
        |                                           
        |                                      OR (SubStatementEntity.authorityActorUid IN (SELECT uid FROM AgentActorUids))
        |                                      OR (SubStatementEntity.contextTeamActorUid IN (SELECT uid FROM AgentActorUids))
        |                                      OR (SubStatementEntity.contextInstructorActorUid IN (SELECT uid FROM AgentActorUids))  
        |                                    )
        |                               )       
        |                          )
        |                     )
        |               )
        |           AND (? = 0 OR XapiStatementEntity.statementVerbUid = ?)
        |               -- Handle activity parameter
        |           AND (      ? = 0
        |                   OR (     XapiStatementEntity.statementObjectType = 5
        |                       AND XapiStatementEntity.statementObjectUid1 = ?)
        |                   OR (     ?    
        |                        AND (    -- As per spec check if substatement activity matches when relatedActivities is set  
        |                                 (     SubStatementEntity.statementObjectType = 5 
        |                                   AND SubStatementEntity.statementObjectUid1 = ?)
        |                                 -- As per spec check if activity uid is part included in context activities.   
        |                               OR (? IN 
        |                                   (SELECT XapiStatementContextActivityJoin.scajToActivityUid
        |                                      FROM XapiStatementContextActivityJoin
        |                                     WHERE (    XapiStatementContextActivityJoin.scajFromStatementIdHi = XapiStatementEntity.statementIdHi
        |                                            AND XapiStatementContextActivityJoin.scajFromStatementIdLo = XapiStatementEntity.statementIdLo)
        |                                        OR (    SubStatementEntity.statementIdHi IS NOT NULL 
        |                                            AND XapiStatementContextActivityJoin.scajFromStatementIdHi = SubStatementEntity.statementIdHi
        |                                            AND XapiStatementContextActivityJoin.scajFromStatementIdLo = SubStatementEntity.statementIdLo)     
        |                                   )
        |                                  )    
        |                            )
        |                      ) 
        |               )          
        |           AND NOT XapiStatementEntity.isSubStatement
        |           AND (    NOT XapiStatementEntity.stmtVoid
        |                 OR (? != 0 AND ? != 0))
        |      ORDER BY CASE(?) WHEN 1 THEN XapiStatementEntity.stored END ASC,
        |               CASE(?) WHEN 0 THEN XapiStatementEntity.stored END DESC
        |         LIMIT ?      
        |
        |        
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 2
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 3
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 4
        _stmt.bindLong(_argIndex, statementIdHi)
        _argIndex = 5
        _stmt.bindLong(_argIndex, statementIdLo)
        _argIndex = 6
        _stmt.bindLong(_argIndex, statementIdHi)
        _argIndex = 7
        _stmt.bindLong(_argIndex, statementIdLo)
        _argIndex = 8
        _stmt.bindLong(_argIndex, voidedStatementIdHi)
        _argIndex = 9
        _stmt.bindLong(_argIndex, voidedStatementIdLo)
        _argIndex = 10
        _stmt.bindLong(_argIndex, voidedStatementIdHi)
        _argIndex = 11
        _stmt.bindLong(_argIndex, voidedStatementIdLo)
        _argIndex = 12
        _stmt.bindLong(_argIndex, since)
        _argIndex = 13
        _stmt.bindLong(_argIndex, since)
        _argIndex = 14
        _stmt.bindLong(_argIndex, until)
        _argIndex = 15
        _stmt.bindLong(_argIndex, until)
        _argIndex = 16
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 17
        val _tmp: Int = if (relatedAgents) 1 else 0
        _stmt.bindLong(_argIndex, _tmp.toLong())
        _argIndex = 18
        _stmt.bindLong(_argIndex, verbUid)
        _argIndex = 19
        _stmt.bindLong(_argIndex, verbUid)
        _argIndex = 20
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 21
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 22
        val _tmp_1: Int = if (relatedActivities) 1 else 0
        _stmt.bindLong(_argIndex, _tmp_1.toLong())
        _argIndex = 23
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 24
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 25
        _stmt.bindLong(_argIndex, voidedStatementIdHi)
        _argIndex = 26
        _stmt.bindLong(_argIndex, voidedStatementIdLo)
        _argIndex = 27
        val _tmp_2: Int = if (ascending) 1 else 0
        _stmt.bindLong(_argIndex, _tmp_2.toLong())
        _argIndex = 28
        val _tmp_3: Int = if (ascending) 1 else 0
        _stmt.bindLong(_argIndex, _tmp_3.toLong())
        _argIndex = 29
        _stmt.bindLong(_argIndex, limit.toLong())
        val _columnIndexOfStatementIdHi: Int = getColumnIndexOrThrow(_stmt, "statementIdHi")
        val _columnIndexOfStatementIdLo: Int = getColumnIndexOrThrow(_stmt, "statementIdLo")
        val _columnIndexOfStatementVerbUid: Int = getColumnIndexOrThrow(_stmt, "statementVerbUid")
        val _columnIndexOfStatementVerbId: Int = getColumnIndexOrThrow(_stmt, "statementVerbId")
        val _columnIndexOfStatementObjectType: Int = getColumnIndexOrThrow(_stmt, "statementObjectType")
        val _columnIndexOfStatementObjectActivityId: Int = getColumnIndexOrThrow(_stmt, "statementObjectActivityId")
        val _columnIndexOfStatementObjectUid1: Int = getColumnIndexOrThrow(_stmt, "statementObjectUid1")
        val _columnIndexOfStatementObjectUid2: Int = getColumnIndexOrThrow(_stmt, "statementObjectUid2")
        val _columnIndexOfStatementActorUid: Int = getColumnIndexOrThrow(_stmt, "statementActorUid")
        val _columnIndexOfAuthorityActorUid: Int = getColumnIndexOrThrow(_stmt, "authorityActorUid")
        val _columnIndexOfResultCompletion: Int = getColumnIndexOrThrow(_stmt, "resultCompletion")
        val _columnIndexOfResultSuccess: Int = getColumnIndexOrThrow(_stmt, "resultSuccess")
        val _columnIndexOfResultScoreScaled: Int = getColumnIndexOrThrow(_stmt, "resultScoreScaled")
        val _columnIndexOfResultScoreRaw: Int = getColumnIndexOrThrow(_stmt, "resultScoreRaw")
        val _columnIndexOfResultScoreMin: Int = getColumnIndexOrThrow(_stmt, "resultScoreMin")
        val _columnIndexOfResultScoreMax: Int = getColumnIndexOrThrow(_stmt, "resultScoreMax")
        val _columnIndexOfResultDuration: Int = getColumnIndexOrThrow(_stmt, "resultDuration")
        val _columnIndexOfResultResponse: Int = getColumnIndexOrThrow(_stmt, "resultResponse")
        val _columnIndexOfResultExtensions: Int = getColumnIndexOrThrow(_stmt, "resultExtensions")
        val _columnIndexOfTimestamp: Int = getColumnIndexOrThrow(_stmt, "timestamp")
        val _columnIndexOfStored: Int = getColumnIndexOrThrow(_stmt, "stored")
        val _columnIndexOfContextRegistrationHi: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationHi")
        val _columnIndexOfContextRegistrationLo: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationLo")
        val _columnIndexOfContextRegistrationHash: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationHash")
        val _columnIndexOfContextLanguage: Int = getColumnIndexOrThrow(_stmt, "contextLanguage")
        val _columnIndexOfContextPlatform: Int = getColumnIndexOrThrow(_stmt, "contextPlatform")
        val _columnIndexOfContextRevision: Int = getColumnIndexOrThrow(_stmt, "contextRevision")
        val _columnIndexOfContextStatementRefIdHi: Int = getColumnIndexOrThrow(_stmt, "contextStatementRefIdHi")
        val _columnIndexOfContextStatementRefIdLo: Int = getColumnIndexOrThrow(_stmt, "contextStatementRefIdLo")
        val _columnIndexOfContextInstructorActorUid: Int = getColumnIndexOrThrow(_stmt, "contextInstructorActorUid")
        val _columnIndexOfContextTeamActorUid: Int = getColumnIndexOrThrow(_stmt, "contextTeamActorUid")
        val _columnIndexOfExtensionProgress: Int = getColumnIndexOrThrow(_stmt, "extensionProgress")
        val _columnIndexOfCompletionOrProgress: Int = getColumnIndexOrThrow(_stmt, "completionOrProgress")
        val _columnIndexOfIsSubStatement: Int = getColumnIndexOrThrow(_stmt, "isSubStatement")
        val _columnIndexOfStatementVersion: Int = getColumnIndexOrThrow(_stmt, "statementVersion")
        val _columnIndexOfStmtVoid: Int = getColumnIndexOrThrow(_stmt, "stmtVoid")
        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: MutableList<XapiStatementAndJsonEntities> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiStatementAndJsonEntities
          val _tmpStmtEntity: XapiStatementEntity
          val _tmpStatementIdHi: Long
          _tmpStatementIdHi = _stmt.getLong(_columnIndexOfStatementIdHi)
          val _tmpStatementIdLo: Long
          _tmpStatementIdLo = _stmt.getLong(_columnIndexOfStatementIdLo)
          val _tmpStatementVerbUid: Long
          _tmpStatementVerbUid = _stmt.getLong(_columnIndexOfStatementVerbUid)
          val _tmpStatementVerbId: String
          _tmpStatementVerbId = _stmt.getText(_columnIndexOfStatementVerbId)
          val _tmpStatementObjectType: XapiStatementEntityObjectTypeEnum
          val _tmp_4: Int
          _tmp_4 = _stmt.getLong(_columnIndexOfStatementObjectType).toInt()
          _tmpStatementObjectType = __schoolTypeConverters.toStatementEntityObjectTypeEnum(_tmp_4)
          val _tmpStatementObjectActivityId: String?
          if (_stmt.isNull(_columnIndexOfStatementObjectActivityId)) {
            _tmpStatementObjectActivityId = null
          } else {
            _tmpStatementObjectActivityId = _stmt.getText(_columnIndexOfStatementObjectActivityId)
          }
          val _tmpStatementObjectUid1: Long
          _tmpStatementObjectUid1 = _stmt.getLong(_columnIndexOfStatementObjectUid1)
          val _tmpStatementObjectUid2: Long
          _tmpStatementObjectUid2 = _stmt.getLong(_columnIndexOfStatementObjectUid2)
          val _tmpStatementActorUid: Long
          _tmpStatementActorUid = _stmt.getLong(_columnIndexOfStatementActorUid)
          val _tmpAuthorityActorUid: Long
          _tmpAuthorityActorUid = _stmt.getLong(_columnIndexOfAuthorityActorUid)
          val _tmpResultCompletion: Boolean?
          val _tmp_5: Int?
          if (_stmt.isNull(_columnIndexOfResultCompletion)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getLong(_columnIndexOfResultCompletion).toInt()
          }
          _tmpResultCompletion = _tmp_5?.let { it != 0 }
          val _tmpResultSuccess: Boolean?
          val _tmp_6: Int?
          if (_stmt.isNull(_columnIndexOfResultSuccess)) {
            _tmp_6 = null
          } else {
            _tmp_6 = _stmt.getLong(_columnIndexOfResultSuccess).toInt()
          }
          _tmpResultSuccess = _tmp_6?.let { it != 0 }
          val _tmpResultScoreScaled: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreScaled)) {
            _tmpResultScoreScaled = null
          } else {
            _tmpResultScoreScaled = _stmt.getDouble(_columnIndexOfResultScoreScaled).toFloat()
          }
          val _tmpResultScoreRaw: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreRaw)) {
            _tmpResultScoreRaw = null
          } else {
            _tmpResultScoreRaw = _stmt.getDouble(_columnIndexOfResultScoreRaw).toFloat()
          }
          val _tmpResultScoreMin: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreMin)) {
            _tmpResultScoreMin = null
          } else {
            _tmpResultScoreMin = _stmt.getDouble(_columnIndexOfResultScoreMin).toFloat()
          }
          val _tmpResultScoreMax: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreMax)) {
            _tmpResultScoreMax = null
          } else {
            _tmpResultScoreMax = _stmt.getDouble(_columnIndexOfResultScoreMax).toFloat()
          }
          val _tmpResultDuration: Long?
          if (_stmt.isNull(_columnIndexOfResultDuration)) {
            _tmpResultDuration = null
          } else {
            _tmpResultDuration = _stmt.getLong(_columnIndexOfResultDuration)
          }
          val _tmpResultResponse: String?
          if (_stmt.isNull(_columnIndexOfResultResponse)) {
            _tmpResultResponse = null
          } else {
            _tmpResultResponse = _stmt.getText(_columnIndexOfResultResponse)
          }
          val _tmpResultExtensions: String?
          if (_stmt.isNull(_columnIndexOfResultExtensions)) {
            _tmpResultExtensions = null
          } else {
            _tmpResultExtensions = _stmt.getText(_columnIndexOfResultExtensions)
          }
          val _tmpTimestamp: Instant?
          val _tmp_7: Long?
          if (_stmt.isNull(_columnIndexOfTimestamp)) {
            _tmp_7 = null
          } else {
            _tmp_7 = _stmt.getLong(_columnIndexOfTimestamp)
          }
          _tmpTimestamp = __sharedConverters.toInstant(_tmp_7)
          val _tmpStored: Instant?
          val _tmp_8: Long?
          if (_stmt.isNull(_columnIndexOfStored)) {
            _tmp_8 = null
          } else {
            _tmp_8 = _stmt.getLong(_columnIndexOfStored)
          }
          _tmpStored = __sharedConverters.toInstant(_tmp_8)
          val _tmpContextRegistrationHi: Long
          _tmpContextRegistrationHi = _stmt.getLong(_columnIndexOfContextRegistrationHi)
          val _tmpContextRegistrationLo: Long
          _tmpContextRegistrationLo = _stmt.getLong(_columnIndexOfContextRegistrationLo)
          val _tmpContextRegistrationHash: Long
          _tmpContextRegistrationHash = _stmt.getLong(_columnIndexOfContextRegistrationHash)
          val _tmpContextLanguage: String?
          if (_stmt.isNull(_columnIndexOfContextLanguage)) {
            _tmpContextLanguage = null
          } else {
            _tmpContextLanguage = _stmt.getText(_columnIndexOfContextLanguage)
          }
          val _tmpContextPlatform: String?
          if (_stmt.isNull(_columnIndexOfContextPlatform)) {
            _tmpContextPlatform = null
          } else {
            _tmpContextPlatform = _stmt.getText(_columnIndexOfContextPlatform)
          }
          val _tmpContextRevision: String?
          if (_stmt.isNull(_columnIndexOfContextRevision)) {
            _tmpContextRevision = null
          } else {
            _tmpContextRevision = _stmt.getText(_columnIndexOfContextRevision)
          }
          val _tmpContextStatementRefIdHi: Long
          _tmpContextStatementRefIdHi = _stmt.getLong(_columnIndexOfContextStatementRefIdHi)
          val _tmpContextStatementRefIdLo: Long
          _tmpContextStatementRefIdLo = _stmt.getLong(_columnIndexOfContextStatementRefIdLo)
          val _tmpContextInstructorActorUid: Long
          _tmpContextInstructorActorUid = _stmt.getLong(_columnIndexOfContextInstructorActorUid)
          val _tmpContextTeamActorUid: Long
          _tmpContextTeamActorUid = _stmt.getLong(_columnIndexOfContextTeamActorUid)
          val _tmpExtensionProgress: Int?
          if (_stmt.isNull(_columnIndexOfExtensionProgress)) {
            _tmpExtensionProgress = null
          } else {
            _tmpExtensionProgress = _stmt.getLong(_columnIndexOfExtensionProgress).toInt()
          }
          val _tmpCompletionOrProgress: Boolean
          val _tmp_9: Int
          _tmp_9 = _stmt.getLong(_columnIndexOfCompletionOrProgress).toInt()
          _tmpCompletionOrProgress = _tmp_9 != 0
          val _tmpIsSubStatement: Boolean
          val _tmp_10: Int
          _tmp_10 = _stmt.getLong(_columnIndexOfIsSubStatement).toInt()
          _tmpIsSubStatement = _tmp_10 != 0
          val _tmpStatementVersion: String?
          if (_stmt.isNull(_columnIndexOfStatementVersion)) {
            _tmpStatementVersion = null
          } else {
            _tmpStatementVersion = _stmt.getText(_columnIndexOfStatementVersion)
          }
          val _tmpStmtVoid: Boolean
          val _tmp_11: Int
          _tmp_11 = _stmt.getLong(_columnIndexOfStmtVoid).toInt()
          _tmpStmtVoid = _tmp_11 != 0
          _tmpStmtEntity = XapiStatementEntity(_tmpStatementIdHi,_tmpStatementIdLo,_tmpStatementVerbUid,_tmpStatementVerbId,_tmpStatementObjectType,_tmpStatementObjectActivityId,_tmpStatementObjectUid1,_tmpStatementObjectUid2,_tmpStatementActorUid,_tmpAuthorityActorUid,_tmpResultCompletion,_tmpResultSuccess,_tmpResultScoreScaled,_tmpResultScoreRaw,_tmpResultScoreMin,_tmpResultScoreMax,_tmpResultDuration,_tmpResultResponse,_tmpResultExtensions,_tmpTimestamp,_tmpStored,_tmpContextRegistrationHi,_tmpContextRegistrationLo,_tmpContextRegistrationHash,_tmpContextLanguage,_tmpContextPlatform,_tmpContextRevision,_tmpContextStatementRefIdHi,_tmpContextStatementRefIdLo,_tmpContextInstructorActorUid,_tmpContextTeamActorUid,_tmpExtensionProgress,_tmpCompletionOrProgress,_tmpIsSubStatement,_tmpStatementVersion,_tmpStmtVoid)
          val _tmpVerbEntity: XapiVerbEntity
          val _tmpVerbUid: Long
          _tmpVerbUid = _stmt.getLong(_columnIndexOfVerbUid)
          val _tmpVerbUrlId: String
          _tmpVerbUrlId = _stmt.getText(_columnIndexOfVerbUrlId)
          val _tmpVerbStatus: StatusEnum
          val _tmp_12: Int
          _tmp_12 = _stmt.getLong(_columnIndexOfVerbStatus).toInt()
          _tmpVerbStatus = __schoolTypeConverters.toStatusEnum(_tmp_12)
          val _tmpVerbLct: Long
          _tmpVerbLct = _stmt.getLong(_columnIndexOfVerbLct)
          _tmpVerbEntity = XapiVerbEntity(_tmpVerbUid,_tmpVerbUrlId,_tmpVerbStatus,_tmpVerbLct)
          _item = XapiStatementAndJsonEntities(_tmpStmtEntity,_tmpVerbEntity)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override fun listAsFlow(
    statementIdHi: Long,
    statementIdLo: Long,
    voidedStatementIdHi: Long,
    voidedStatementIdLo: Long,
    agentUid: Long,
    verbUid: Long,
    activityUid: Long,
    relatedAgents: Boolean,
    relatedActivities: Boolean,
    since: Long,
    until: Long,
    ascending: Boolean,
    limit: Int,
  ): Flow<List<XapiStatementAndJsonEntities>> {
    val _sql: String = """
        |
        |            
        |            -- Get a list of all the actors that should be considered as related to agent parameter
        |            -- Eg the actor uid itself and any group members
        |          WITH AgentActorUids(uid) AS
        |               (SELECT ? AS uid
        |                 UNION
        |                SELECT XapiGroupMemberActorJoin.gmajGroupActorUid AS uid
        |                  FROM XapiGroupMemberActorJoin
        |                 WHERE ? != 0 
        |                   AND XapiGroupMemberActorJoin.gmajMemberActorUid = ?)
        |            
        |            
        |        SELECT XapiStatementEntity.*, XapiVerbEntity.*
        |          FROM XapiStatementEntity
        |               JOIN XapiVerbEntity
        |                    ON (    XapiVerbEntity.verbUid = XapiStatementEntity.statementVerbUid)
        |               LEFT JOIN XapiStatementEntity AS SubStatementEntity
        |                    ON (    XapiStatementEntity.statementObjectType = 4
        |                        AND SubStatementEntity.statementIdHi = XapiStatementEntity.statementObjectUid1
        |                        AND SubStatementEntity.statementIdLo = XapiStatementEntity.statementObjectUid2)
        |         WHERE (   (? = 0 AND ? = 0) 
        |                OR (     XapiStatementEntity.statementIdHi = ? 
        |                     AND XapiStatementEntity.statementIdLo = ?))
        |           AND (   (? = 0 AND ? = 0)
        |                OR (     XapiStatementEntity.statementIdHi = ? 
        |                     AND XapiStatementEntity.statementIdLo = ?
        |                     AND XapiStatementEntity.stmtVoid))
        |           AND (? = -9223372036854775808 OR XapiStatementEntity.stored > ?)
        |           AND (? = 9223372036854775807 OR XapiStatementEntity.stored <= ?)
        |           -- Handle agent parameter
        |           AND (    ? = 0 
        |                  OR (    XapiStatementEntity.statementActorUid IN 
        |                          (SELECT uid FROM AgentActorUids))
        |                  OR (    (    XapiStatementEntity.statementObjectType = 1
        |                            OR XapiStatementEntity.statementObjectType = 2)
        |                      AND (XapiStatementEntity.statementObjectUid1 IN (SELECT uid FROM AgentActorUids)))
        |                  -- Handle related agents        
        |                  OR (    ? 
        |                      AND (    XapiStatementEntity.authorityActorUid IN (SELECT uid FROM AgentActorUids)
        |                            OR XapiStatementEntity.contextTeamActorUid IN (SELECT uid FROM AgentActorUids)
        |                            OR XapiStatementEntity.contextInstructorActorUid IN (SELECT uid FROM AgentActorUids)
        |                            -- check substatement if applicable
        |                            OR (     SubStatementEntity.statementActorUid IS NOT NULL
        |                                AND (    SubStatementEntity.statementActorUid IN (SELECT uid FROM AgentActorUids)
        |                                      OR (     (   SubStatementEntity.statementObjectType = 1
        |                                                OR SubStatementEntity.statementObjectType = 2)
        |                                           AND (SubStatementEntity.statementObjectUid1 IN (SELECT uid FROM AgentActorUids)))
        |                                           
        |                                      OR (SubStatementEntity.authorityActorUid IN (SELECT uid FROM AgentActorUids))
        |                                      OR (SubStatementEntity.contextTeamActorUid IN (SELECT uid FROM AgentActorUids))
        |                                      OR (SubStatementEntity.contextInstructorActorUid IN (SELECT uid FROM AgentActorUids))  
        |                                    )
        |                               )       
        |                          )
        |                     )
        |               )
        |           AND (? = 0 OR XapiStatementEntity.statementVerbUid = ?)
        |               -- Handle activity parameter
        |           AND (      ? = 0
        |                   OR (     XapiStatementEntity.statementObjectType = 5
        |                       AND XapiStatementEntity.statementObjectUid1 = ?)
        |                   OR (     ?    
        |                        AND (    -- As per spec check if substatement activity matches when relatedActivities is set  
        |                                 (     SubStatementEntity.statementObjectType = 5 
        |                                   AND SubStatementEntity.statementObjectUid1 = ?)
        |                                 -- As per spec check if activity uid is part included in context activities.   
        |                               OR (? IN 
        |                                   (SELECT XapiStatementContextActivityJoin.scajToActivityUid
        |                                      FROM XapiStatementContextActivityJoin
        |                                     WHERE (    XapiStatementContextActivityJoin.scajFromStatementIdHi = XapiStatementEntity.statementIdHi
        |                                            AND XapiStatementContextActivityJoin.scajFromStatementIdLo = XapiStatementEntity.statementIdLo)
        |                                        OR (    SubStatementEntity.statementIdHi IS NOT NULL 
        |                                            AND XapiStatementContextActivityJoin.scajFromStatementIdHi = SubStatementEntity.statementIdHi
        |                                            AND XapiStatementContextActivityJoin.scajFromStatementIdLo = SubStatementEntity.statementIdLo)     
        |                                   )
        |                                  )    
        |                            )
        |                      ) 
        |               )          
        |           AND NOT XapiStatementEntity.isSubStatement
        |           AND (    NOT XapiStatementEntity.stmtVoid
        |                 OR (? != 0 AND ? != 0))
        |      ORDER BY CASE(?) WHEN 1 THEN XapiStatementEntity.stored END ASC,
        |               CASE(?) WHEN 0 THEN XapiStatementEntity.stored END DESC
        |         LIMIT ?      
        |
        |        
        """.trimMargin()
    return createFlow(__db, false, arrayOf("XapiGroupMemberActorJoin", "XapiStatementEntity", "XapiVerbEntity", "XapiStatementContextActivityJoin")) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 2
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 3
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 4
        _stmt.bindLong(_argIndex, statementIdHi)
        _argIndex = 5
        _stmt.bindLong(_argIndex, statementIdLo)
        _argIndex = 6
        _stmt.bindLong(_argIndex, statementIdHi)
        _argIndex = 7
        _stmt.bindLong(_argIndex, statementIdLo)
        _argIndex = 8
        _stmt.bindLong(_argIndex, voidedStatementIdHi)
        _argIndex = 9
        _stmt.bindLong(_argIndex, voidedStatementIdLo)
        _argIndex = 10
        _stmt.bindLong(_argIndex, voidedStatementIdHi)
        _argIndex = 11
        _stmt.bindLong(_argIndex, voidedStatementIdLo)
        _argIndex = 12
        _stmt.bindLong(_argIndex, since)
        _argIndex = 13
        _stmt.bindLong(_argIndex, since)
        _argIndex = 14
        _stmt.bindLong(_argIndex, until)
        _argIndex = 15
        _stmt.bindLong(_argIndex, until)
        _argIndex = 16
        _stmt.bindLong(_argIndex, agentUid)
        _argIndex = 17
        val _tmp: Int = if (relatedAgents) 1 else 0
        _stmt.bindLong(_argIndex, _tmp.toLong())
        _argIndex = 18
        _stmt.bindLong(_argIndex, verbUid)
        _argIndex = 19
        _stmt.bindLong(_argIndex, verbUid)
        _argIndex = 20
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 21
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 22
        val _tmp_1: Int = if (relatedActivities) 1 else 0
        _stmt.bindLong(_argIndex, _tmp_1.toLong())
        _argIndex = 23
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 24
        _stmt.bindLong(_argIndex, activityUid)
        _argIndex = 25
        _stmt.bindLong(_argIndex, voidedStatementIdHi)
        _argIndex = 26
        _stmt.bindLong(_argIndex, voidedStatementIdLo)
        _argIndex = 27
        val _tmp_2: Int = if (ascending) 1 else 0
        _stmt.bindLong(_argIndex, _tmp_2.toLong())
        _argIndex = 28
        val _tmp_3: Int = if (ascending) 1 else 0
        _stmt.bindLong(_argIndex, _tmp_3.toLong())
        _argIndex = 29
        _stmt.bindLong(_argIndex, limit.toLong())
        val _columnIndexOfStatementIdHi: Int = getColumnIndexOrThrow(_stmt, "statementIdHi")
        val _columnIndexOfStatementIdLo: Int = getColumnIndexOrThrow(_stmt, "statementIdLo")
        val _columnIndexOfStatementVerbUid: Int = getColumnIndexOrThrow(_stmt, "statementVerbUid")
        val _columnIndexOfStatementVerbId: Int = getColumnIndexOrThrow(_stmt, "statementVerbId")
        val _columnIndexOfStatementObjectType: Int = getColumnIndexOrThrow(_stmt, "statementObjectType")
        val _columnIndexOfStatementObjectActivityId: Int = getColumnIndexOrThrow(_stmt, "statementObjectActivityId")
        val _columnIndexOfStatementObjectUid1: Int = getColumnIndexOrThrow(_stmt, "statementObjectUid1")
        val _columnIndexOfStatementObjectUid2: Int = getColumnIndexOrThrow(_stmt, "statementObjectUid2")
        val _columnIndexOfStatementActorUid: Int = getColumnIndexOrThrow(_stmt, "statementActorUid")
        val _columnIndexOfAuthorityActorUid: Int = getColumnIndexOrThrow(_stmt, "authorityActorUid")
        val _columnIndexOfResultCompletion: Int = getColumnIndexOrThrow(_stmt, "resultCompletion")
        val _columnIndexOfResultSuccess: Int = getColumnIndexOrThrow(_stmt, "resultSuccess")
        val _columnIndexOfResultScoreScaled: Int = getColumnIndexOrThrow(_stmt, "resultScoreScaled")
        val _columnIndexOfResultScoreRaw: Int = getColumnIndexOrThrow(_stmt, "resultScoreRaw")
        val _columnIndexOfResultScoreMin: Int = getColumnIndexOrThrow(_stmt, "resultScoreMin")
        val _columnIndexOfResultScoreMax: Int = getColumnIndexOrThrow(_stmt, "resultScoreMax")
        val _columnIndexOfResultDuration: Int = getColumnIndexOrThrow(_stmt, "resultDuration")
        val _columnIndexOfResultResponse: Int = getColumnIndexOrThrow(_stmt, "resultResponse")
        val _columnIndexOfResultExtensions: Int = getColumnIndexOrThrow(_stmt, "resultExtensions")
        val _columnIndexOfTimestamp: Int = getColumnIndexOrThrow(_stmt, "timestamp")
        val _columnIndexOfStored: Int = getColumnIndexOrThrow(_stmt, "stored")
        val _columnIndexOfContextRegistrationHi: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationHi")
        val _columnIndexOfContextRegistrationLo: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationLo")
        val _columnIndexOfContextRegistrationHash: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationHash")
        val _columnIndexOfContextLanguage: Int = getColumnIndexOrThrow(_stmt, "contextLanguage")
        val _columnIndexOfContextPlatform: Int = getColumnIndexOrThrow(_stmt, "contextPlatform")
        val _columnIndexOfContextRevision: Int = getColumnIndexOrThrow(_stmt, "contextRevision")
        val _columnIndexOfContextStatementRefIdHi: Int = getColumnIndexOrThrow(_stmt, "contextStatementRefIdHi")
        val _columnIndexOfContextStatementRefIdLo: Int = getColumnIndexOrThrow(_stmt, "contextStatementRefIdLo")
        val _columnIndexOfContextInstructorActorUid: Int = getColumnIndexOrThrow(_stmt, "contextInstructorActorUid")
        val _columnIndexOfContextTeamActorUid: Int = getColumnIndexOrThrow(_stmt, "contextTeamActorUid")
        val _columnIndexOfExtensionProgress: Int = getColumnIndexOrThrow(_stmt, "extensionProgress")
        val _columnIndexOfCompletionOrProgress: Int = getColumnIndexOrThrow(_stmt, "completionOrProgress")
        val _columnIndexOfIsSubStatement: Int = getColumnIndexOrThrow(_stmt, "isSubStatement")
        val _columnIndexOfStatementVersion: Int = getColumnIndexOrThrow(_stmt, "statementVersion")
        val _columnIndexOfStmtVoid: Int = getColumnIndexOrThrow(_stmt, "stmtVoid")
        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: MutableList<XapiStatementAndJsonEntities> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiStatementAndJsonEntities
          val _tmpStmtEntity: XapiStatementEntity
          val _tmpStatementIdHi: Long
          _tmpStatementIdHi = _stmt.getLong(_columnIndexOfStatementIdHi)
          val _tmpStatementIdLo: Long
          _tmpStatementIdLo = _stmt.getLong(_columnIndexOfStatementIdLo)
          val _tmpStatementVerbUid: Long
          _tmpStatementVerbUid = _stmt.getLong(_columnIndexOfStatementVerbUid)
          val _tmpStatementVerbId: String
          _tmpStatementVerbId = _stmt.getText(_columnIndexOfStatementVerbId)
          val _tmpStatementObjectType: XapiStatementEntityObjectTypeEnum
          val _tmp_4: Int
          _tmp_4 = _stmt.getLong(_columnIndexOfStatementObjectType).toInt()
          _tmpStatementObjectType = __schoolTypeConverters.toStatementEntityObjectTypeEnum(_tmp_4)
          val _tmpStatementObjectActivityId: String?
          if (_stmt.isNull(_columnIndexOfStatementObjectActivityId)) {
            _tmpStatementObjectActivityId = null
          } else {
            _tmpStatementObjectActivityId = _stmt.getText(_columnIndexOfStatementObjectActivityId)
          }
          val _tmpStatementObjectUid1: Long
          _tmpStatementObjectUid1 = _stmt.getLong(_columnIndexOfStatementObjectUid1)
          val _tmpStatementObjectUid2: Long
          _tmpStatementObjectUid2 = _stmt.getLong(_columnIndexOfStatementObjectUid2)
          val _tmpStatementActorUid: Long
          _tmpStatementActorUid = _stmt.getLong(_columnIndexOfStatementActorUid)
          val _tmpAuthorityActorUid: Long
          _tmpAuthorityActorUid = _stmt.getLong(_columnIndexOfAuthorityActorUid)
          val _tmpResultCompletion: Boolean?
          val _tmp_5: Int?
          if (_stmt.isNull(_columnIndexOfResultCompletion)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getLong(_columnIndexOfResultCompletion).toInt()
          }
          _tmpResultCompletion = _tmp_5?.let { it != 0 }
          val _tmpResultSuccess: Boolean?
          val _tmp_6: Int?
          if (_stmt.isNull(_columnIndexOfResultSuccess)) {
            _tmp_6 = null
          } else {
            _tmp_6 = _stmt.getLong(_columnIndexOfResultSuccess).toInt()
          }
          _tmpResultSuccess = _tmp_6?.let { it != 0 }
          val _tmpResultScoreScaled: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreScaled)) {
            _tmpResultScoreScaled = null
          } else {
            _tmpResultScoreScaled = _stmt.getDouble(_columnIndexOfResultScoreScaled).toFloat()
          }
          val _tmpResultScoreRaw: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreRaw)) {
            _tmpResultScoreRaw = null
          } else {
            _tmpResultScoreRaw = _stmt.getDouble(_columnIndexOfResultScoreRaw).toFloat()
          }
          val _tmpResultScoreMin: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreMin)) {
            _tmpResultScoreMin = null
          } else {
            _tmpResultScoreMin = _stmt.getDouble(_columnIndexOfResultScoreMin).toFloat()
          }
          val _tmpResultScoreMax: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreMax)) {
            _tmpResultScoreMax = null
          } else {
            _tmpResultScoreMax = _stmt.getDouble(_columnIndexOfResultScoreMax).toFloat()
          }
          val _tmpResultDuration: Long?
          if (_stmt.isNull(_columnIndexOfResultDuration)) {
            _tmpResultDuration = null
          } else {
            _tmpResultDuration = _stmt.getLong(_columnIndexOfResultDuration)
          }
          val _tmpResultResponse: String?
          if (_stmt.isNull(_columnIndexOfResultResponse)) {
            _tmpResultResponse = null
          } else {
            _tmpResultResponse = _stmt.getText(_columnIndexOfResultResponse)
          }
          val _tmpResultExtensions: String?
          if (_stmt.isNull(_columnIndexOfResultExtensions)) {
            _tmpResultExtensions = null
          } else {
            _tmpResultExtensions = _stmt.getText(_columnIndexOfResultExtensions)
          }
          val _tmpTimestamp: Instant?
          val _tmp_7: Long?
          if (_stmt.isNull(_columnIndexOfTimestamp)) {
            _tmp_7 = null
          } else {
            _tmp_7 = _stmt.getLong(_columnIndexOfTimestamp)
          }
          _tmpTimestamp = __sharedConverters.toInstant(_tmp_7)
          val _tmpStored: Instant?
          val _tmp_8: Long?
          if (_stmt.isNull(_columnIndexOfStored)) {
            _tmp_8 = null
          } else {
            _tmp_8 = _stmt.getLong(_columnIndexOfStored)
          }
          _tmpStored = __sharedConverters.toInstant(_tmp_8)
          val _tmpContextRegistrationHi: Long
          _tmpContextRegistrationHi = _stmt.getLong(_columnIndexOfContextRegistrationHi)
          val _tmpContextRegistrationLo: Long
          _tmpContextRegistrationLo = _stmt.getLong(_columnIndexOfContextRegistrationLo)
          val _tmpContextRegistrationHash: Long
          _tmpContextRegistrationHash = _stmt.getLong(_columnIndexOfContextRegistrationHash)
          val _tmpContextLanguage: String?
          if (_stmt.isNull(_columnIndexOfContextLanguage)) {
            _tmpContextLanguage = null
          } else {
            _tmpContextLanguage = _stmt.getText(_columnIndexOfContextLanguage)
          }
          val _tmpContextPlatform: String?
          if (_stmt.isNull(_columnIndexOfContextPlatform)) {
            _tmpContextPlatform = null
          } else {
            _tmpContextPlatform = _stmt.getText(_columnIndexOfContextPlatform)
          }
          val _tmpContextRevision: String?
          if (_stmt.isNull(_columnIndexOfContextRevision)) {
            _tmpContextRevision = null
          } else {
            _tmpContextRevision = _stmt.getText(_columnIndexOfContextRevision)
          }
          val _tmpContextStatementRefIdHi: Long
          _tmpContextStatementRefIdHi = _stmt.getLong(_columnIndexOfContextStatementRefIdHi)
          val _tmpContextStatementRefIdLo: Long
          _tmpContextStatementRefIdLo = _stmt.getLong(_columnIndexOfContextStatementRefIdLo)
          val _tmpContextInstructorActorUid: Long
          _tmpContextInstructorActorUid = _stmt.getLong(_columnIndexOfContextInstructorActorUid)
          val _tmpContextTeamActorUid: Long
          _tmpContextTeamActorUid = _stmt.getLong(_columnIndexOfContextTeamActorUid)
          val _tmpExtensionProgress: Int?
          if (_stmt.isNull(_columnIndexOfExtensionProgress)) {
            _tmpExtensionProgress = null
          } else {
            _tmpExtensionProgress = _stmt.getLong(_columnIndexOfExtensionProgress).toInt()
          }
          val _tmpCompletionOrProgress: Boolean
          val _tmp_9: Int
          _tmp_9 = _stmt.getLong(_columnIndexOfCompletionOrProgress).toInt()
          _tmpCompletionOrProgress = _tmp_9 != 0
          val _tmpIsSubStatement: Boolean
          val _tmp_10: Int
          _tmp_10 = _stmt.getLong(_columnIndexOfIsSubStatement).toInt()
          _tmpIsSubStatement = _tmp_10 != 0
          val _tmpStatementVersion: String?
          if (_stmt.isNull(_columnIndexOfStatementVersion)) {
            _tmpStatementVersion = null
          } else {
            _tmpStatementVersion = _stmt.getText(_columnIndexOfStatementVersion)
          }
          val _tmpStmtVoid: Boolean
          val _tmp_11: Int
          _tmp_11 = _stmt.getLong(_columnIndexOfStmtVoid).toInt()
          _tmpStmtVoid = _tmp_11 != 0
          _tmpStmtEntity = XapiStatementEntity(_tmpStatementIdHi,_tmpStatementIdLo,_tmpStatementVerbUid,_tmpStatementVerbId,_tmpStatementObjectType,_tmpStatementObjectActivityId,_tmpStatementObjectUid1,_tmpStatementObjectUid2,_tmpStatementActorUid,_tmpAuthorityActorUid,_tmpResultCompletion,_tmpResultSuccess,_tmpResultScoreScaled,_tmpResultScoreRaw,_tmpResultScoreMin,_tmpResultScoreMax,_tmpResultDuration,_tmpResultResponse,_tmpResultExtensions,_tmpTimestamp,_tmpStored,_tmpContextRegistrationHi,_tmpContextRegistrationLo,_tmpContextRegistrationHash,_tmpContextLanguage,_tmpContextPlatform,_tmpContextRevision,_tmpContextStatementRefIdHi,_tmpContextStatementRefIdLo,_tmpContextInstructorActorUid,_tmpContextTeamActorUid,_tmpExtensionProgress,_tmpCompletionOrProgress,_tmpIsSubStatement,_tmpStatementVersion,_tmpStmtVoid)
          val _tmpVerbEntity: XapiVerbEntity
          val _tmpVerbUid: Long
          _tmpVerbUid = _stmt.getLong(_columnIndexOfVerbUid)
          val _tmpVerbUrlId: String
          _tmpVerbUrlId = _stmt.getText(_columnIndexOfVerbUrlId)
          val _tmpVerbStatus: StatusEnum
          val _tmp_12: Int
          _tmp_12 = _stmt.getLong(_columnIndexOfVerbStatus).toInt()
          _tmpVerbStatus = __schoolTypeConverters.toStatusEnum(_tmp_12)
          val _tmpVerbLct: Long
          _tmpVerbLct = _stmt.getLong(_columnIndexOfVerbLct)
          _tmpVerbEntity = XapiVerbEntity(_tmpVerbUid,_tmpVerbUrlId,_tmpVerbStatus,_tmpVerbLct)
          _item = XapiStatementAndJsonEntities(_tmpStmtEntity,_tmpVerbEntity)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun getEntityForSubstatement(subStatementIdHi: Long, subStatementIdLo: Long): XapiSubstatementAndVerbEntity {
    val _sql: String = """
        |
        |        SELECT XapiStatementEntity.*, XapiVerbEntity.*
        |          FROM XapiStatementEntity
        |               JOIN XapiVerbEntity
        |                    ON (    XapiVerbEntity.verbUid = XapiStatementEntity.statementVerbUid)
        |         WHERE XapiStatementEntity.statementIdHi = ?
        |           AND XapiStatementEntity.statementIdLo = ?
        |           AND XapiStatementEntity.isSubStatement
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, subStatementIdHi)
        _argIndex = 2
        _stmt.bindLong(_argIndex, subStatementIdLo)
        val _columnIndexOfStatementIdHi: Int = getColumnIndexOrThrow(_stmt, "statementIdHi")
        val _columnIndexOfStatementIdLo: Int = getColumnIndexOrThrow(_stmt, "statementIdLo")
        val _columnIndexOfStatementVerbUid: Int = getColumnIndexOrThrow(_stmt, "statementVerbUid")
        val _columnIndexOfStatementVerbId: Int = getColumnIndexOrThrow(_stmt, "statementVerbId")
        val _columnIndexOfStatementObjectType: Int = getColumnIndexOrThrow(_stmt, "statementObjectType")
        val _columnIndexOfStatementObjectActivityId: Int = getColumnIndexOrThrow(_stmt, "statementObjectActivityId")
        val _columnIndexOfStatementObjectUid1: Int = getColumnIndexOrThrow(_stmt, "statementObjectUid1")
        val _columnIndexOfStatementObjectUid2: Int = getColumnIndexOrThrow(_stmt, "statementObjectUid2")
        val _columnIndexOfStatementActorUid: Int = getColumnIndexOrThrow(_stmt, "statementActorUid")
        val _columnIndexOfAuthorityActorUid: Int = getColumnIndexOrThrow(_stmt, "authorityActorUid")
        val _columnIndexOfResultCompletion: Int = getColumnIndexOrThrow(_stmt, "resultCompletion")
        val _columnIndexOfResultSuccess: Int = getColumnIndexOrThrow(_stmt, "resultSuccess")
        val _columnIndexOfResultScoreScaled: Int = getColumnIndexOrThrow(_stmt, "resultScoreScaled")
        val _columnIndexOfResultScoreRaw: Int = getColumnIndexOrThrow(_stmt, "resultScoreRaw")
        val _columnIndexOfResultScoreMin: Int = getColumnIndexOrThrow(_stmt, "resultScoreMin")
        val _columnIndexOfResultScoreMax: Int = getColumnIndexOrThrow(_stmt, "resultScoreMax")
        val _columnIndexOfResultDuration: Int = getColumnIndexOrThrow(_stmt, "resultDuration")
        val _columnIndexOfResultResponse: Int = getColumnIndexOrThrow(_stmt, "resultResponse")
        val _columnIndexOfResultExtensions: Int = getColumnIndexOrThrow(_stmt, "resultExtensions")
        val _columnIndexOfTimestamp: Int = getColumnIndexOrThrow(_stmt, "timestamp")
        val _columnIndexOfStored: Int = getColumnIndexOrThrow(_stmt, "stored")
        val _columnIndexOfContextRegistrationHi: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationHi")
        val _columnIndexOfContextRegistrationLo: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationLo")
        val _columnIndexOfContextRegistrationHash: Int = getColumnIndexOrThrow(_stmt, "contextRegistrationHash")
        val _columnIndexOfContextLanguage: Int = getColumnIndexOrThrow(_stmt, "contextLanguage")
        val _columnIndexOfContextPlatform: Int = getColumnIndexOrThrow(_stmt, "contextPlatform")
        val _columnIndexOfContextRevision: Int = getColumnIndexOrThrow(_stmt, "contextRevision")
        val _columnIndexOfContextStatementRefIdHi: Int = getColumnIndexOrThrow(_stmt, "contextStatementRefIdHi")
        val _columnIndexOfContextStatementRefIdLo: Int = getColumnIndexOrThrow(_stmt, "contextStatementRefIdLo")
        val _columnIndexOfContextInstructorActorUid: Int = getColumnIndexOrThrow(_stmt, "contextInstructorActorUid")
        val _columnIndexOfContextTeamActorUid: Int = getColumnIndexOrThrow(_stmt, "contextTeamActorUid")
        val _columnIndexOfExtensionProgress: Int = getColumnIndexOrThrow(_stmt, "extensionProgress")
        val _columnIndexOfCompletionOrProgress: Int = getColumnIndexOrThrow(_stmt, "completionOrProgress")
        val _columnIndexOfIsSubStatement: Int = getColumnIndexOrThrow(_stmt, "isSubStatement")
        val _columnIndexOfStatementVersion: Int = getColumnIndexOrThrow(_stmt, "statementVersion")
        val _columnIndexOfStmtVoid: Int = getColumnIndexOrThrow(_stmt, "stmtVoid")
        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: XapiSubstatementAndVerbEntity
        if (_stmt.step()) {
          val _tmpStmtEntity: XapiStatementEntity
          val _tmpStatementIdHi: Long
          _tmpStatementIdHi = _stmt.getLong(_columnIndexOfStatementIdHi)
          val _tmpStatementIdLo: Long
          _tmpStatementIdLo = _stmt.getLong(_columnIndexOfStatementIdLo)
          val _tmpStatementVerbUid: Long
          _tmpStatementVerbUid = _stmt.getLong(_columnIndexOfStatementVerbUid)
          val _tmpStatementVerbId: String
          _tmpStatementVerbId = _stmt.getText(_columnIndexOfStatementVerbId)
          val _tmpStatementObjectType: XapiStatementEntityObjectTypeEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfStatementObjectType).toInt()
          _tmpStatementObjectType = __schoolTypeConverters.toStatementEntityObjectTypeEnum(_tmp)
          val _tmpStatementObjectActivityId: String?
          if (_stmt.isNull(_columnIndexOfStatementObjectActivityId)) {
            _tmpStatementObjectActivityId = null
          } else {
            _tmpStatementObjectActivityId = _stmt.getText(_columnIndexOfStatementObjectActivityId)
          }
          val _tmpStatementObjectUid1: Long
          _tmpStatementObjectUid1 = _stmt.getLong(_columnIndexOfStatementObjectUid1)
          val _tmpStatementObjectUid2: Long
          _tmpStatementObjectUid2 = _stmt.getLong(_columnIndexOfStatementObjectUid2)
          val _tmpStatementActorUid: Long
          _tmpStatementActorUid = _stmt.getLong(_columnIndexOfStatementActorUid)
          val _tmpAuthorityActorUid: Long
          _tmpAuthorityActorUid = _stmt.getLong(_columnIndexOfAuthorityActorUid)
          val _tmpResultCompletion: Boolean?
          val _tmp_1: Int?
          if (_stmt.isNull(_columnIndexOfResultCompletion)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfResultCompletion).toInt()
          }
          _tmpResultCompletion = _tmp_1?.let { it != 0 }
          val _tmpResultSuccess: Boolean?
          val _tmp_2: Int?
          if (_stmt.isNull(_columnIndexOfResultSuccess)) {
            _tmp_2 = null
          } else {
            _tmp_2 = _stmt.getLong(_columnIndexOfResultSuccess).toInt()
          }
          _tmpResultSuccess = _tmp_2?.let { it != 0 }
          val _tmpResultScoreScaled: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreScaled)) {
            _tmpResultScoreScaled = null
          } else {
            _tmpResultScoreScaled = _stmt.getDouble(_columnIndexOfResultScoreScaled).toFloat()
          }
          val _tmpResultScoreRaw: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreRaw)) {
            _tmpResultScoreRaw = null
          } else {
            _tmpResultScoreRaw = _stmt.getDouble(_columnIndexOfResultScoreRaw).toFloat()
          }
          val _tmpResultScoreMin: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreMin)) {
            _tmpResultScoreMin = null
          } else {
            _tmpResultScoreMin = _stmt.getDouble(_columnIndexOfResultScoreMin).toFloat()
          }
          val _tmpResultScoreMax: Float?
          if (_stmt.isNull(_columnIndexOfResultScoreMax)) {
            _tmpResultScoreMax = null
          } else {
            _tmpResultScoreMax = _stmt.getDouble(_columnIndexOfResultScoreMax).toFloat()
          }
          val _tmpResultDuration: Long?
          if (_stmt.isNull(_columnIndexOfResultDuration)) {
            _tmpResultDuration = null
          } else {
            _tmpResultDuration = _stmt.getLong(_columnIndexOfResultDuration)
          }
          val _tmpResultResponse: String?
          if (_stmt.isNull(_columnIndexOfResultResponse)) {
            _tmpResultResponse = null
          } else {
            _tmpResultResponse = _stmt.getText(_columnIndexOfResultResponse)
          }
          val _tmpResultExtensions: String?
          if (_stmt.isNull(_columnIndexOfResultExtensions)) {
            _tmpResultExtensions = null
          } else {
            _tmpResultExtensions = _stmt.getText(_columnIndexOfResultExtensions)
          }
          val _tmpTimestamp: Instant?
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfTimestamp)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfTimestamp)
          }
          _tmpTimestamp = __sharedConverters.toInstant(_tmp_3)
          val _tmpStored: Instant?
          val _tmp_4: Long?
          if (_stmt.isNull(_columnIndexOfStored)) {
            _tmp_4 = null
          } else {
            _tmp_4 = _stmt.getLong(_columnIndexOfStored)
          }
          _tmpStored = __sharedConverters.toInstant(_tmp_4)
          val _tmpContextRegistrationHi: Long
          _tmpContextRegistrationHi = _stmt.getLong(_columnIndexOfContextRegistrationHi)
          val _tmpContextRegistrationLo: Long
          _tmpContextRegistrationLo = _stmt.getLong(_columnIndexOfContextRegistrationLo)
          val _tmpContextRegistrationHash: Long
          _tmpContextRegistrationHash = _stmt.getLong(_columnIndexOfContextRegistrationHash)
          val _tmpContextLanguage: String?
          if (_stmt.isNull(_columnIndexOfContextLanguage)) {
            _tmpContextLanguage = null
          } else {
            _tmpContextLanguage = _stmt.getText(_columnIndexOfContextLanguage)
          }
          val _tmpContextPlatform: String?
          if (_stmt.isNull(_columnIndexOfContextPlatform)) {
            _tmpContextPlatform = null
          } else {
            _tmpContextPlatform = _stmt.getText(_columnIndexOfContextPlatform)
          }
          val _tmpContextRevision: String?
          if (_stmt.isNull(_columnIndexOfContextRevision)) {
            _tmpContextRevision = null
          } else {
            _tmpContextRevision = _stmt.getText(_columnIndexOfContextRevision)
          }
          val _tmpContextStatementRefIdHi: Long
          _tmpContextStatementRefIdHi = _stmt.getLong(_columnIndexOfContextStatementRefIdHi)
          val _tmpContextStatementRefIdLo: Long
          _tmpContextStatementRefIdLo = _stmt.getLong(_columnIndexOfContextStatementRefIdLo)
          val _tmpContextInstructorActorUid: Long
          _tmpContextInstructorActorUid = _stmt.getLong(_columnIndexOfContextInstructorActorUid)
          val _tmpContextTeamActorUid: Long
          _tmpContextTeamActorUid = _stmt.getLong(_columnIndexOfContextTeamActorUid)
          val _tmpExtensionProgress: Int?
          if (_stmt.isNull(_columnIndexOfExtensionProgress)) {
            _tmpExtensionProgress = null
          } else {
            _tmpExtensionProgress = _stmt.getLong(_columnIndexOfExtensionProgress).toInt()
          }
          val _tmpCompletionOrProgress: Boolean
          val _tmp_5: Int
          _tmp_5 = _stmt.getLong(_columnIndexOfCompletionOrProgress).toInt()
          _tmpCompletionOrProgress = _tmp_5 != 0
          val _tmpIsSubStatement: Boolean
          val _tmp_6: Int
          _tmp_6 = _stmt.getLong(_columnIndexOfIsSubStatement).toInt()
          _tmpIsSubStatement = _tmp_6 != 0
          val _tmpStatementVersion: String?
          if (_stmt.isNull(_columnIndexOfStatementVersion)) {
            _tmpStatementVersion = null
          } else {
            _tmpStatementVersion = _stmt.getText(_columnIndexOfStatementVersion)
          }
          val _tmpStmtVoid: Boolean
          val _tmp_7: Int
          _tmp_7 = _stmt.getLong(_columnIndexOfStmtVoid).toInt()
          _tmpStmtVoid = _tmp_7 != 0
          _tmpStmtEntity = XapiStatementEntity(_tmpStatementIdHi,_tmpStatementIdLo,_tmpStatementVerbUid,_tmpStatementVerbId,_tmpStatementObjectType,_tmpStatementObjectActivityId,_tmpStatementObjectUid1,_tmpStatementObjectUid2,_tmpStatementActorUid,_tmpAuthorityActorUid,_tmpResultCompletion,_tmpResultSuccess,_tmpResultScoreScaled,_tmpResultScoreRaw,_tmpResultScoreMin,_tmpResultScoreMax,_tmpResultDuration,_tmpResultResponse,_tmpResultExtensions,_tmpTimestamp,_tmpStored,_tmpContextRegistrationHi,_tmpContextRegistrationLo,_tmpContextRegistrationHash,_tmpContextLanguage,_tmpContextPlatform,_tmpContextRevision,_tmpContextStatementRefIdHi,_tmpContextStatementRefIdLo,_tmpContextInstructorActorUid,_tmpContextTeamActorUid,_tmpExtensionProgress,_tmpCompletionOrProgress,_tmpIsSubStatement,_tmpStatementVersion,_tmpStmtVoid)
          val _tmpVerbEntity: XapiVerbEntity
          val _tmpVerbUid: Long
          _tmpVerbUid = _stmt.getLong(_columnIndexOfVerbUid)
          val _tmpVerbUrlId: String
          _tmpVerbUrlId = _stmt.getText(_columnIndexOfVerbUrlId)
          val _tmpVerbStatus: StatusEnum
          val _tmp_8: Int
          _tmp_8 = _stmt.getLong(_columnIndexOfVerbStatus).toInt()
          _tmpVerbStatus = __schoolTypeConverters.toStatusEnum(_tmp_8)
          val _tmpVerbLct: Long
          _tmpVerbLct = _stmt.getLong(_columnIndexOfVerbLct)
          _tmpVerbEntity = XapiVerbEntity(_tmpVerbUid,_tmpVerbUrlId,_tmpVerbStatus,_tmpVerbLct)
          _result = XapiSubstatementAndVerbEntity(_tmpStmtEntity,_tmpVerbEntity)
        } else {
          error("The query result was empty, but expected a single row to return a NON-NULL object of type 'world.respect.datalayer.db.school.xapi.composites.XapiSubstatementAndVerbEntity'.")
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun getTimestampsByUuid(statementIdHi: Long, statementIdLo: Long): XapiTimes? {
    val _sql: String = """
        |
        |        SELECT XapiStatementEntity.stored AS timeStored,
        |               XapiStatementEntity.timestamp AS timestamp
        |          FROM XapiStatementEntity
        |         WHERE XapiStatementEntity.statementIdHi = ?
        |           AND XapiStatementEntity.statementIdLo = ?
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, statementIdHi)
        _argIndex = 2
        _stmt.bindLong(_argIndex, statementIdLo)
        val _columnIndexOfTimeStored: Int = 0
        val _columnIndexOfTimestamp: Int = 1
        val _result: XapiTimes?
        if (_stmt.step()) {
          val _tmpTimeStored: Long
          _tmpTimeStored = _stmt.getLong(_columnIndexOfTimeStored)
          val _tmpTimestamp: Long
          _tmpTimestamp = _stmt.getLong(_columnIndexOfTimestamp)
          _result = XapiTimes(_tmpTimeStored,_tmpTimestamp)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun getVerbUidNumToBeVoided(statementIdHi: Long, statementIdLo: Long): Long? {
    val _sql: String = """
        |
        |        SELECT XapiStatementEntity.statementVerbUid
        |          FROM XapiStatementEntity
        |         WHERE XapiStatementEntity.statementIdHi = ?
        |           AND XapiStatementEntity.statementIdLo = ?
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, statementIdHi)
        _argIndex = 2
        _stmt.bindLong(_argIndex, statementIdLo)
        val _result: Long?
        if (_stmt.step()) {
          if (_stmt.isNull(0)) {
            _result = null
          } else {
            _result = _stmt.getLong(0)
          }
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override fun getAssignmentProgressFlow(assignmentActivityUidNum: Long): Flow<List<XapiAssignmentProgressEntityRow>> {
    val _sql: String = """
        |
        |        SELECT 
        |            Stmt.statementActorUid AS personUid,
        |            Actor.actorName AS personName,
        |            Stmt.statementObjectActivityId AS activityId,
        |            MAX(Stmt.resultCompletion) AS completion,
        |            MAX(Stmt.resultSuccess) AS success,
        |            MAX(COALESCE(Stmt.resultScoreScaled, Stmt.resultScoreRaw)) AS scoreScaled,
        |            MAX(Stmt.extensionProgress) AS progress
        |        FROM XapiStatementEntity Stmt
        |        JOIN XapiActorEntity Actor ON Stmt.statementActorUid = Actor.actorUid
        |        JOIN XapiStatementContextActivityJoin CtxJoin ON (Stmt.statementIdHi = CtxJoin.scajFromStatementIdHi AND Stmt.statementIdLo = CtxJoin.scajFromStatementIdLo)
        |        WHERE CtxJoin.scajToActivityUid = ?
        |        GROUP BY Stmt.statementActorUid, Stmt.statementObjectActivityId
        |    
        """.trimMargin()
    return createFlow(__db, false, arrayOf("XapiStatementEntity", "XapiActorEntity", "XapiStatementContextActivityJoin")) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, assignmentActivityUidNum)
        val _columnIndexOfPersonUid: Int = 0
        val _columnIndexOfPersonName: Int = 1
        val _columnIndexOfActivityId: Int = 2
        val _columnIndexOfCompletion: Int = 3
        val _columnIndexOfSuccess: Int = 4
        val _columnIndexOfScoreScaled: Int = 5
        val _columnIndexOfProgress: Int = 6
        val _result: MutableList<XapiAssignmentProgressEntityRow> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiAssignmentProgressEntityRow
          val _tmpPersonUid: String
          _tmpPersonUid = _stmt.getText(_columnIndexOfPersonUid)
          val _tmpPersonName: String?
          if (_stmt.isNull(_columnIndexOfPersonName)) {
            _tmpPersonName = null
          } else {
            _tmpPersonName = _stmt.getText(_columnIndexOfPersonName)
          }
          val _tmpActivityId: String
          _tmpActivityId = _stmt.getText(_columnIndexOfActivityId)
          val _tmpCompletion: Boolean?
          val _tmp: Int?
          if (_stmt.isNull(_columnIndexOfCompletion)) {
            _tmp = null
          } else {
            _tmp = _stmt.getLong(_columnIndexOfCompletion).toInt()
          }
          _tmpCompletion = _tmp?.let { it != 0 }
          val _tmpSuccess: Boolean?
          val _tmp_1: Int?
          if (_stmt.isNull(_columnIndexOfSuccess)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfSuccess).toInt()
          }
          _tmpSuccess = _tmp_1?.let { it != 0 }
          val _tmpScoreScaled: Float?
          if (_stmt.isNull(_columnIndexOfScoreScaled)) {
            _tmpScoreScaled = null
          } else {
            _tmpScoreScaled = _stmt.getDouble(_columnIndexOfScoreScaled).toFloat()
          }
          val _tmpProgress: Int?
          if (_stmt.isNull(_columnIndexOfProgress)) {
            _tmpProgress = null
          } else {
            _tmpProgress = _stmt.getLong(_columnIndexOfProgress).toInt()
          }
          _item = XapiAssignmentProgressEntityRow(_tmpPersonUid,_tmpPersonName,_tmpActivityId,_tmpCompletion,_tmpSuccess,_tmpScoreScaled,_tmpProgress)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override fun getAssignmentSummariesFlow(
    assignVerbId: String,
    recipeActivityUid: Long,
    deadlineExtKey: String,
  ): Flow<List<XapiAssignmentSummaryEntityRow>> {
    val _sql: String = """
        |
        |        SELECT 
        |            AssignStmt.statementObjectActivityId AS activityId,
        |            (SELECT almeValue FROM XapiActivityLangMapEntry WHERE almeActivityUid = AssignStmt.statementObjectUid1 AND almeProperty = 1 LIMIT 1) AS title,
        |            Actor.actorName AS className,
        |            CAST(strftime('%s', AssignStmt.timestamp) AS LONG) * 1000 AS lastModified,
        |            (SELECT aeeJson FROM XapiActivityExtensionEntity WHERE aeeActivityUid = AssignStmt.statementObjectUid1 AND aeeKey = ? LIMIT 1) AS deadlineJson,
        |            (SELECT COUNT(DISTINCT Stmt.statementActorUid) 
        |             FROM XapiStatementEntity Stmt 
        |             WHERE Stmt.statementObjectActivityId = AssignStmt.statementObjectActivityId 
        |               AND Stmt.resultCompletion = 1) AS completedCount,
        |            (SELECT COUNT(DISTINCT Stmt.statementActorUid) 
        |             FROM XapiStatementEntity Stmt 
        |             WHERE Stmt.statementObjectActivityId = AssignStmt.statementObjectActivityId) AS totalCount,
        |            (SELECT GROUP_CONCAT(scajToActivityId) 
        |             FROM XapiStatementContextActivityJoin 
        |             WHERE scajFromStatementIdHi = AssignStmt.statementIdHi 
        |               AND scajFromStatementIdLo = AssignStmt.statementIdLo 
        |               AND scajContextType = 2) AS learningUnitsConcat
        |        FROM XapiStatementEntity AssignStmt
        |        JOIN XapiActorEntity Actor ON AssignStmt.statementActorUid = Actor.actorUid
        |        JOIN XapiStatementContextActivityJoin CtxJoin ON (AssignStmt.statementIdHi = CtxJoin.scajFromStatementIdHi AND AssignStmt.statementIdLo = CtxJoin.scajFromStatementIdLo)
        |        WHERE AssignStmt.statementVerbId = ?
        |          AND CtxJoin.scajToActivityUid = ?
        |          AND NOT AssignStmt.isSubStatement
        |          AND NOT AssignStmt.stmtVoid
        |        GROUP BY AssignStmt.statementObjectActivityId
        |        ORDER BY AssignStmt.timestamp DESC
        |    
        """.trimMargin()
    return createFlow(__db, false, arrayOf("XapiActivityLangMapEntry", "XapiActivityExtensionEntity", "XapiStatementEntity", "XapiStatementContextActivityJoin", "XapiActorEntity")) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindText(_argIndex, deadlineExtKey)
        _argIndex = 2
        _stmt.bindText(_argIndex, assignVerbId)
        _argIndex = 3
        _stmt.bindLong(_argIndex, recipeActivityUid)
        val _columnIndexOfActivityId: Int = 0
        val _columnIndexOfTitle: Int = 1
        val _columnIndexOfClassName: Int = 2
        val _columnIndexOfLastModified: Int = 3
        val _columnIndexOfDeadlineJson: Int = 4
        val _columnIndexOfCompletedCount: Int = 5
        val _columnIndexOfTotalCount: Int = 6
        val _columnIndexOfLearningUnitsConcat: Int = 7
        val _result: MutableList<XapiAssignmentSummaryEntityRow> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiAssignmentSummaryEntityRow
          val _tmpActivityId: String
          _tmpActivityId = _stmt.getText(_columnIndexOfActivityId)
          val _tmpTitle: String?
          if (_stmt.isNull(_columnIndexOfTitle)) {
            _tmpTitle = null
          } else {
            _tmpTitle = _stmt.getText(_columnIndexOfTitle)
          }
          val _tmpClassName: String?
          if (_stmt.isNull(_columnIndexOfClassName)) {
            _tmpClassName = null
          } else {
            _tmpClassName = _stmt.getText(_columnIndexOfClassName)
          }
          val _tmpLastModified: Long
          _tmpLastModified = _stmt.getLong(_columnIndexOfLastModified)
          val _tmpDeadlineJson: String?
          if (_stmt.isNull(_columnIndexOfDeadlineJson)) {
            _tmpDeadlineJson = null
          } else {
            _tmpDeadlineJson = _stmt.getText(_columnIndexOfDeadlineJson)
          }
          val _tmpCompletedCount: Int
          _tmpCompletedCount = _stmt.getLong(_columnIndexOfCompletedCount).toInt()
          val _tmpTotalCount: Int
          _tmpTotalCount = _stmt.getLong(_columnIndexOfTotalCount).toInt()
          val _tmpLearningUnitsConcat: String?
          if (_stmt.isNull(_columnIndexOfLearningUnitsConcat)) {
            _tmpLearningUnitsConcat = null
          } else {
            _tmpLearningUnitsConcat = _stmt.getText(_columnIndexOfLearningUnitsConcat)
          }
          _item = XapiAssignmentSummaryEntityRow(_tmpActivityId,_tmpTitle,_tmpClassName,_tmpLastModified,_tmpDeadlineJson,_tmpCompletedCount,_tmpTotalCount,_tmpLearningUnitsConcat)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun getLastStoredTimestampForActivity(activityUidNum: Long): Long? {
    val _sql: String = "SELECT MAX(stored) FROM XapiStatementEntity Stmt JOIN XapiStatementContextActivityJoin CtxJoin ON (Stmt.statementIdHi = CtxJoin.scajFromStatementIdHi AND Stmt.statementIdLo = CtxJoin.scajFromStatementIdLo) WHERE CtxJoin.scajToActivityUid = ?"
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, activityUidNum)
        val _result: Long?
        if (_stmt.step()) {
          val _tmp: Long?
          if (_stmt.isNull(0)) {
            _tmp = null
          } else {
            _tmp = _stmt.getLong(0)
          }
          _result = _tmp
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun updateSetStatementVoided(voidStmtIdHi: Long, voidStmtIdLo: Long) {
    val _sql: String = """
        |
        |        UPDATE XapiStatementEntity
        |           SET stmtVoid = 1
        |         WHERE XapiStatementEntity.statementIdHi = ?
        |           AND XapiStatementEntity.statementIdLo = ?
        |    
        """.trimMargin()
    return performSuspending(__db, false, true) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, voidStmtIdHi)
        _argIndex = 2
        _stmt.bindLong(_argIndex, voidStmtIdLo)
        _stmt.step()
      } finally {
        _stmt.close()
      }
    }
  }

  public override suspend fun runReportQuery(query: RoomRawQuery): List<StatementReportRow> {
    val _sql: String = query.sql
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        query.getBindingFunction().invoke(_stmt)
        val _columnIndexOfYAxis: Int = getColumnIndex(_stmt, "yAxis")
        val _columnIndexOfXAxis: Int = getColumnIndex(_stmt, "xAxis")
        val _columnIndexOfSubgroup: Int = getColumnIndex(_stmt, "subgroup")
        val _result: MutableList<StatementReportRow> = mutableListOf()
        while (_stmt.step()) {
          val _item: StatementReportRow
          val _tmpYAxis: Double
          if (_columnIndexOfYAxis == -1) {
            _tmpYAxis = 0.0
          } else {
            _tmpYAxis = _stmt.getDouble(_columnIndexOfYAxis)
          }
          val _tmpXAxis: String
          if (_columnIndexOfXAxis == -1) {
            error("Missing column 'xAxis' for a NON-NULL value, column not found in result.")
          } else {
            _tmpXAxis = _stmt.getText(_columnIndexOfXAxis)
          }
          val _tmpSubgroup: String
          if (_columnIndexOfSubgroup == -1) {
            error("Missing column 'subgroup' for a NON-NULL value, column not found in result.")
          } else {
            _tmpSubgroup = _stmt.getText(_columnIndexOfSubgroup)
          }
          _item = StatementReportRow(_tmpYAxis,_tmpXAxis,_tmpSubgroup)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

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