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.XapiAssignmentResultRow
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.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 suspend fun getAssignmentResults(assignmentActivityIdNum: Long): List<XapiAssignmentResultRow> {
    val _sql: String = """
        |
        |        WITH LatestAssignmentStatementIds(idHi, idLo, actorUid) AS (
        |                 SELECT XapiStatementEntity.statementIdHi AS idHi,
        |                        XapiStatementEntity.statementIdLo AS idLo,
        |                        XapiStatementEntity.statementActorUid AS actorUid
        |                   FROM XapiStatementEntity
        |                  WHERE XapiStatementEntity.statementObjectUid1 = ?
        |                    AND XapiStatementEntity.statementObjectType = 5
        |                    AND NOT XapiStatementEntity.stmtVoid
        |               ORDER BY XapiStatementEntity.timestamp DESC
        |                  LIMIT 1),
        |             
        |             AgentActorUids(uid) AS (
        |                   SELECT (SELECT actorUid FROM LatestAssignmentStatementIds) AS uid
        |                     UNION
        |                    SELECT XapiGroupMemberActorJoin.gmajMemberActorUid AS uid
        |                      FROM XapiGroupMemberActorJoin
        |                     WHERE XapiGroupMemberActorJoin.gmajMemberActorUid = 
        |                           (SELECT actorUid FROM LatestAssignmentStatementIds)),
        |             
        |             AssignedActivityUids(assignedActivityUid) AS (
        |                    SELECT XapiStatementContextActivityJoin.scajToActivityUid AS assignedActivityUid
        |                      FROM XapiStatementContextActivityJoin
        |                    WHERE XapiStatementContextActivityJoin.scajFromStatementIdHi = 
        |                          (SELECT idHi FROM LatestAssignmentStatementIds)
        |                      AND XapiStatementContextActivityJoin.scajFromStatementIdLo = 
        |                          (SELECT idLo FROM LatestAssignmentStatementIds)  
        |             )
        |
        |             -- Use aggregate functions with Group by actor, activity to get the required progress
        |             -- info per actor and activity.
        |             SELECT XapiStatementEntity.statementActorUid AS actorUid,
        |                    XapiStatementEntity.statementObjectUid1 AS activityUid,
        |                    MAX(XapiStatementEntity.extensionProgress) AS progress,
        |                    MAX(XapiStatementEntity.resultCompletion) AS completed,
        |                    MAX(XapiStatementEntity.resultSuccess) AS successful,
        |                    MAX(XapiStatementEntity.resultScoreScaled) AS rawScore
        |               FROM XapiStatementEntity
        |              WHERE XapiStatementEntity.statementObjectUid1 IN(
        |                    SELECT DISTINCT AssignedActivityUids.assignedActivityUid 
        |                      FROM AssignedActivityUids)
        |                AND XapiStatementEntity.statementObjectType = 5
        |                AND NOT XapiStatementEntity.stmtVoid
        |                AND XapiStatementEntity.statementActorUid IN 
        |                    (SELECT uid FROM AgentActorUids)
        |           GROUP BY XapiStatementEntity.statementActorUid, XapiStatementEntity.statementObjectUid1
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, assignmentActivityIdNum)
        val _columnIndexOfActorUid: Int = 0
        val _columnIndexOfActivityUid: Int = 1
        val _columnIndexOfProgress: Int = 2
        val _columnIndexOfCompleted: Int = 3
        val _columnIndexOfSuccessful: Int = 4
        val _columnIndexOfRawScore: Int = 5
        val _result: MutableList<XapiAssignmentResultRow> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiAssignmentResultRow
          val _tmpActorUid: Long
          _tmpActorUid = _stmt.getLong(_columnIndexOfActorUid)
          val _tmpActivityUid: Long
          _tmpActivityUid = _stmt.getLong(_columnIndexOfActivityUid)
          val _tmpProgress: Int?
          if (_stmt.isNull(_columnIndexOfProgress)) {
            _tmpProgress = null
          } else {
            _tmpProgress = _stmt.getLong(_columnIndexOfProgress).toInt()
          }
          val _tmpCompleted: Boolean?
          val _tmp: Int?
          if (_stmt.isNull(_columnIndexOfCompleted)) {
            _tmp = null
          } else {
            _tmp = _stmt.getLong(_columnIndexOfCompleted).toInt()
          }
          _tmpCompleted = _tmp?.let { it != 0 }
          val _tmpSuccessful: Boolean?
          val _tmp_1: Int?
          if (_stmt.isNull(_columnIndexOfSuccessful)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfSuccessful).toInt()
          }
          _tmpSuccessful = _tmp_1?.let { it != 0 }
          val _tmpRawScore: Float?
          if (_stmt.isNull(_columnIndexOfRawScore)) {
            _tmpRawScore = null
          } else {
            _tmpRawScore = _stmt.getDouble(_columnIndexOfRawScore).toFloat()
          }
          _item = XapiAssignmentResultRow(_tmpActorUid,_tmpActivityUid,_tmpProgress,_tmpCompleted,_tmpSuccessful,_tmpRawScore)
          _result.add(_item)
        }
        _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()
  }
}
