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

import androidx.paging.PagingSource
import androidx.room.EntityInsertAdapter
import androidx.room.RoomDatabase
import androidx.room.RoomRawQuery
import androidx.room.coroutines.createFlow
import androidx.room.paging.LimitOffsetPagingSource
import androidx.room.util.appendPlaceholders
import androidx.room.util.getColumnIndexOrThrow
import androidx.room.util.performSuspending
import androidx.sqlite.SQLiteStatement
import javax.`annotation`.processing.Generated
import kotlin.Int
import kotlin.Long
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.MutableList
import kotlin.collections.mutableListOf
import kotlin.reflect.KClass
import kotlin.text.StringBuilder
import kotlin.time.Instant
import kotlinx.coroutines.flow.Flow
import kotlinx.datetime.LocalDate
import kotlinx.serialization.json.JsonObject
import world.respect.datalayer.db.school.SchoolTypeConverters
import world.respect.datalayer.db.school.entities.EnrollmentEntity
import world.respect.datalayer.db.shared.SharedConverters
import world.respect.datalayer.school.model.EnrollmentRoleEnum
import world.respect.datalayer.school.model.StatusEnum

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

  private val __insertAdapterOfEnrollmentEntity: EntityInsertAdapter<EnrollmentEntity>

  private val __schoolTypeConverters: SchoolTypeConverters = SchoolTypeConverters()

  private val __sharedConverters: SharedConverters = SharedConverters()
  init {
    this.__db = __db
    this.__insertAdapterOfEnrollmentEntity = object : EntityInsertAdapter<EnrollmentEntity>() {
      protected override fun createQuery(): String = "INSERT OR REPLACE INTO `EnrollmentEntity` (`eUid`,`eUidNum`,`eStatus`,`eLastModified`,`eStored`,`eMetadata`,`eClassUid`,`eClassUidNum`,`ePersonUid`,`ePersonUidNum`,`eRole`,`eBeginDate`,`eEndDate`,`eInviteCode`,`eApprovedByPersonUidNum`,`eApprovedByPersonUid`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: EnrollmentEntity) {
        statement.bindText(1, entity.eUid)
        statement.bindLong(2, entity.eUidNum)
        val _tmp: Int = __schoolTypeConverters.fromStatusEnum(entity.eStatus)
        statement.bindLong(3, _tmp.toLong())
        val _tmp_1: Long? = __sharedConverters.fromInstant(entity.eLastModified)
        if (_tmp_1 == null) {
          statement.bindNull(4)
        } else {
          statement.bindLong(4, _tmp_1)
        }
        val _tmp_2: Long? = __sharedConverters.fromInstant(entity.eStored)
        if (_tmp_2 == null) {
          statement.bindNull(5)
        } else {
          statement.bindLong(5, _tmp_2)
        }
        val _tmpEMetadata: JsonObject? = entity.eMetadata
        val _tmp_3: String? = __schoolTypeConverters.fromJsonObject(_tmpEMetadata)
        if (_tmp_3 == null) {
          statement.bindNull(6)
        } else {
          statement.bindText(6, _tmp_3)
        }
        statement.bindText(7, entity.eClassUid)
        statement.bindLong(8, entity.eClassUidNum)
        statement.bindText(9, entity.ePersonUid)
        statement.bindLong(10, entity.ePersonUidNum)
        val _tmp_4: Int = __schoolTypeConverters.fromEnrollmentRoleEnum(entity.eRole)
        statement.bindLong(11, _tmp_4.toLong())
        val _tmpEBeginDate: LocalDate? = entity.eBeginDate
        val _tmp_5: Long? = __schoolTypeConverters.fromLocalDate(_tmpEBeginDate)
        if (_tmp_5 == null) {
          statement.bindNull(12)
        } else {
          statement.bindLong(12, _tmp_5)
        }
        val _tmpEEndDate: LocalDate? = entity.eEndDate
        val _tmp_6: Long? = __schoolTypeConverters.fromLocalDate(_tmpEEndDate)
        if (_tmp_6 == null) {
          statement.bindNull(13)
        } else {
          statement.bindLong(13, _tmp_6)
        }
        val _tmpEInviteCode: String? = entity.eInviteCode
        if (_tmpEInviteCode == null) {
          statement.bindNull(14)
        } else {
          statement.bindText(14, _tmpEInviteCode)
        }
        statement.bindLong(15, entity.eApprovedByPersonUidNum)
        val _tmpEApprovedByPersonUid: String? = entity.eApprovedByPersonUid
        if (_tmpEApprovedByPersonUid == null) {
          statement.bindNull(16)
        } else {
          statement.bindText(16, _tmpEApprovedByPersonUid)
        }
      }
    }
  }

  public override suspend fun upsert(enrolments: List<EnrollmentEntity>): Unit = performSuspending(__db, false, true) { _connection ->
    __insertAdapterOfEnrollmentEntity.insert(_connection, enrolments)
  }

  public override suspend fun findByGuid(uidNum: Long): EnrollmentEntity? {
    val _sql: String = """
        |
        |        SELECT EnrollmentEntity.*
        |          FROM EnrollmentEntity
        |         WHERE EnrollmentEntity.eUidNum = ?
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, uidNum)
        val _columnIndexOfEUid: Int = getColumnIndexOrThrow(_stmt, "eUid")
        val _columnIndexOfEUidNum: Int = getColumnIndexOrThrow(_stmt, "eUidNum")
        val _columnIndexOfEStatus: Int = getColumnIndexOrThrow(_stmt, "eStatus")
        val _columnIndexOfELastModified: Int = getColumnIndexOrThrow(_stmt, "eLastModified")
        val _columnIndexOfEStored: Int = getColumnIndexOrThrow(_stmt, "eStored")
        val _columnIndexOfEMetadata: Int = getColumnIndexOrThrow(_stmt, "eMetadata")
        val _columnIndexOfEClassUid: Int = getColumnIndexOrThrow(_stmt, "eClassUid")
        val _columnIndexOfEClassUidNum: Int = getColumnIndexOrThrow(_stmt, "eClassUidNum")
        val _columnIndexOfEPersonUid: Int = getColumnIndexOrThrow(_stmt, "ePersonUid")
        val _columnIndexOfEPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "ePersonUidNum")
        val _columnIndexOfERole: Int = getColumnIndexOrThrow(_stmt, "eRole")
        val _columnIndexOfEBeginDate: Int = getColumnIndexOrThrow(_stmt, "eBeginDate")
        val _columnIndexOfEEndDate: Int = getColumnIndexOrThrow(_stmt, "eEndDate")
        val _columnIndexOfEInviteCode: Int = getColumnIndexOrThrow(_stmt, "eInviteCode")
        val _columnIndexOfEApprovedByPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUidNum")
        val _columnIndexOfEApprovedByPersonUid: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUid")
        val _result: EnrollmentEntity?
        if (_stmt.step()) {
          val _tmpEUid: String
          _tmpEUid = _stmt.getText(_columnIndexOfEUid)
          val _tmpEUidNum: Long
          _tmpEUidNum = _stmt.getLong(_columnIndexOfEUidNum)
          val _tmpEStatus: StatusEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfEStatus).toInt()
          _tmpEStatus = __schoolTypeConverters.toStatusEnum(_tmp)
          val _tmpELastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfELastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfELastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpELastModified = _tmp_2
          }
          val _tmpEStored: Instant
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfEStored)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfEStored)
          }
          val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
          if (_tmp_4 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpEStored = _tmp_4
          }
          val _tmpEMetadata: JsonObject?
          val _tmp_5: String?
          if (_stmt.isNull(_columnIndexOfEMetadata)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getText(_columnIndexOfEMetadata)
          }
          _tmpEMetadata = __schoolTypeConverters.toJsonObject(_tmp_5)
          val _tmpEClassUid: String
          _tmpEClassUid = _stmt.getText(_columnIndexOfEClassUid)
          val _tmpEClassUidNum: Long
          _tmpEClassUidNum = _stmt.getLong(_columnIndexOfEClassUidNum)
          val _tmpEPersonUid: String
          _tmpEPersonUid = _stmt.getText(_columnIndexOfEPersonUid)
          val _tmpEPersonUidNum: Long
          _tmpEPersonUidNum = _stmt.getLong(_columnIndexOfEPersonUidNum)
          val _tmpERole: EnrollmentRoleEnum
          val _tmp_6: Int
          _tmp_6 = _stmt.getLong(_columnIndexOfERole).toInt()
          _tmpERole = __schoolTypeConverters.toEnrollmentRoleEnum(_tmp_6)
          val _tmpEBeginDate: LocalDate?
          val _tmp_7: Long?
          if (_stmt.isNull(_columnIndexOfEBeginDate)) {
            _tmp_7 = null
          } else {
            _tmp_7 = _stmt.getLong(_columnIndexOfEBeginDate)
          }
          _tmpEBeginDate = __schoolTypeConverters.toLocalDate(_tmp_7)
          val _tmpEEndDate: LocalDate?
          val _tmp_8: Long?
          if (_stmt.isNull(_columnIndexOfEEndDate)) {
            _tmp_8 = null
          } else {
            _tmp_8 = _stmt.getLong(_columnIndexOfEEndDate)
          }
          _tmpEEndDate = __schoolTypeConverters.toLocalDate(_tmp_8)
          val _tmpEInviteCode: String?
          if (_stmt.isNull(_columnIndexOfEInviteCode)) {
            _tmpEInviteCode = null
          } else {
            _tmpEInviteCode = _stmt.getText(_columnIndexOfEInviteCode)
          }
          val _tmpEApprovedByPersonUidNum: Long
          _tmpEApprovedByPersonUidNum = _stmt.getLong(_columnIndexOfEApprovedByPersonUidNum)
          val _tmpEApprovedByPersonUid: String?
          if (_stmt.isNull(_columnIndexOfEApprovedByPersonUid)) {
            _tmpEApprovedByPersonUid = null
          } else {
            _tmpEApprovedByPersonUid = _stmt.getText(_columnIndexOfEApprovedByPersonUid)
          }
          _result = EnrollmentEntity(_tmpEUid,_tmpEUidNum,_tmpEStatus,_tmpELastModified,_tmpEStored,_tmpEMetadata,_tmpEClassUid,_tmpEClassUidNum,_tmpEPersonUid,_tmpEPersonUidNum,_tmpERole,_tmpEBeginDate,_tmpEEndDate,_tmpEInviteCode,_tmpEApprovedByPersonUidNum,_tmpEApprovedByPersonUid)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override fun findByGuidAsFlow(uidNum: Long): Flow<EnrollmentEntity?> {
    val _sql: String = """
        |
        |        SELECT EnrollmentEntity.*
        |          FROM EnrollmentEntity
        |         WHERE EnrollmentEntity.eUidNum = ?
        |    
        """.trimMargin()
    return createFlow(__db, false, arrayOf("EnrollmentEntity")) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, uidNum)
        val _columnIndexOfEUid: Int = getColumnIndexOrThrow(_stmt, "eUid")
        val _columnIndexOfEUidNum: Int = getColumnIndexOrThrow(_stmt, "eUidNum")
        val _columnIndexOfEStatus: Int = getColumnIndexOrThrow(_stmt, "eStatus")
        val _columnIndexOfELastModified: Int = getColumnIndexOrThrow(_stmt, "eLastModified")
        val _columnIndexOfEStored: Int = getColumnIndexOrThrow(_stmt, "eStored")
        val _columnIndexOfEMetadata: Int = getColumnIndexOrThrow(_stmt, "eMetadata")
        val _columnIndexOfEClassUid: Int = getColumnIndexOrThrow(_stmt, "eClassUid")
        val _columnIndexOfEClassUidNum: Int = getColumnIndexOrThrow(_stmt, "eClassUidNum")
        val _columnIndexOfEPersonUid: Int = getColumnIndexOrThrow(_stmt, "ePersonUid")
        val _columnIndexOfEPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "ePersonUidNum")
        val _columnIndexOfERole: Int = getColumnIndexOrThrow(_stmt, "eRole")
        val _columnIndexOfEBeginDate: Int = getColumnIndexOrThrow(_stmt, "eBeginDate")
        val _columnIndexOfEEndDate: Int = getColumnIndexOrThrow(_stmt, "eEndDate")
        val _columnIndexOfEInviteCode: Int = getColumnIndexOrThrow(_stmt, "eInviteCode")
        val _columnIndexOfEApprovedByPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUidNum")
        val _columnIndexOfEApprovedByPersonUid: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUid")
        val _result: EnrollmentEntity?
        if (_stmt.step()) {
          val _tmpEUid: String
          _tmpEUid = _stmt.getText(_columnIndexOfEUid)
          val _tmpEUidNum: Long
          _tmpEUidNum = _stmt.getLong(_columnIndexOfEUidNum)
          val _tmpEStatus: StatusEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfEStatus).toInt()
          _tmpEStatus = __schoolTypeConverters.toStatusEnum(_tmp)
          val _tmpELastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfELastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfELastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpELastModified = _tmp_2
          }
          val _tmpEStored: Instant
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfEStored)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfEStored)
          }
          val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
          if (_tmp_4 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpEStored = _tmp_4
          }
          val _tmpEMetadata: JsonObject?
          val _tmp_5: String?
          if (_stmt.isNull(_columnIndexOfEMetadata)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getText(_columnIndexOfEMetadata)
          }
          _tmpEMetadata = __schoolTypeConverters.toJsonObject(_tmp_5)
          val _tmpEClassUid: String
          _tmpEClassUid = _stmt.getText(_columnIndexOfEClassUid)
          val _tmpEClassUidNum: Long
          _tmpEClassUidNum = _stmt.getLong(_columnIndexOfEClassUidNum)
          val _tmpEPersonUid: String
          _tmpEPersonUid = _stmt.getText(_columnIndexOfEPersonUid)
          val _tmpEPersonUidNum: Long
          _tmpEPersonUidNum = _stmt.getLong(_columnIndexOfEPersonUidNum)
          val _tmpERole: EnrollmentRoleEnum
          val _tmp_6: Int
          _tmp_6 = _stmt.getLong(_columnIndexOfERole).toInt()
          _tmpERole = __schoolTypeConverters.toEnrollmentRoleEnum(_tmp_6)
          val _tmpEBeginDate: LocalDate?
          val _tmp_7: Long?
          if (_stmt.isNull(_columnIndexOfEBeginDate)) {
            _tmp_7 = null
          } else {
            _tmp_7 = _stmt.getLong(_columnIndexOfEBeginDate)
          }
          _tmpEBeginDate = __schoolTypeConverters.toLocalDate(_tmp_7)
          val _tmpEEndDate: LocalDate?
          val _tmp_8: Long?
          if (_stmt.isNull(_columnIndexOfEEndDate)) {
            _tmp_8 = null
          } else {
            _tmp_8 = _stmt.getLong(_columnIndexOfEEndDate)
          }
          _tmpEEndDate = __schoolTypeConverters.toLocalDate(_tmp_8)
          val _tmpEInviteCode: String?
          if (_stmt.isNull(_columnIndexOfEInviteCode)) {
            _tmpEInviteCode = null
          } else {
            _tmpEInviteCode = _stmt.getText(_columnIndexOfEInviteCode)
          }
          val _tmpEApprovedByPersonUidNum: Long
          _tmpEApprovedByPersonUidNum = _stmt.getLong(_columnIndexOfEApprovedByPersonUidNum)
          val _tmpEApprovedByPersonUid: String?
          if (_stmt.isNull(_columnIndexOfEApprovedByPersonUid)) {
            _tmpEApprovedByPersonUid = null
          } else {
            _tmpEApprovedByPersonUid = _stmt.getText(_columnIndexOfEApprovedByPersonUid)
          }
          _result = EnrollmentEntity(_tmpEUid,_tmpEUidNum,_tmpEStatus,_tmpELastModified,_tmpEStored,_tmpEMetadata,_tmpEClassUid,_tmpEClassUidNum,_tmpEPersonUid,_tmpEPersonUidNum,_tmpERole,_tmpEBeginDate,_tmpEEndDate,_tmpEInviteCode,_tmpEApprovedByPersonUidNum,_tmpEApprovedByPersonUid)
        } else {
          _result = null
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

  public override fun listAsPagingSource(
    since: Long,
    uidNum: Long,
    classUidNum: Long,
    classUidRoleFlag: Int,
    personUidNum: Long,
  ): PagingSource<Int, EnrollmentEntity> {
    val _sql: String = """
        |
        |        SELECT EnrollmentEntity.*
        |          FROM EnrollmentEntity
        |         WHERE (? <= 0 OR EnrollmentEntity.eStored > ?)
        |           AND (? = 0 OR EnrollmentEntity.eUidNum = ?)
        |           AND (? = 0 OR EnrollmentEntity.eClassUidNum = ?)
        |           AND (? = 0 OR EnrollmentEntity.eRole = ?)
        |           AND (? = 0 OR EnrollmentEntity.ePersonUidNum = ?)
        |    
        """.trimMargin()
    val _rawQuery: RoomRawQuery = RoomRawQuery(_sql) { _stmt ->
      var _argIndex: Int = 1
      _stmt.bindLong(_argIndex, since)
      _argIndex = 2
      _stmt.bindLong(_argIndex, since)
      _argIndex = 3
      _stmt.bindLong(_argIndex, uidNum)
      _argIndex = 4
      _stmt.bindLong(_argIndex, uidNum)
      _argIndex = 5
      _stmt.bindLong(_argIndex, classUidNum)
      _argIndex = 6
      _stmt.bindLong(_argIndex, classUidNum)
      _argIndex = 7
      _stmt.bindLong(_argIndex, classUidRoleFlag.toLong())
      _argIndex = 8
      _stmt.bindLong(_argIndex, classUidRoleFlag.toLong())
      _argIndex = 9
      _stmt.bindLong(_argIndex, personUidNum)
      _argIndex = 10
      _stmt.bindLong(_argIndex, personUidNum)
    }
    return object : LimitOffsetPagingSource<EnrollmentEntity>(_rawQuery, __db, "EnrollmentEntity") {
      protected override suspend fun convertRows(limitOffsetQuery: RoomRawQuery, itemCount: Int): List<EnrollmentEntity> = performSuspending(__db, true, false) { _connection ->
        val _stmt: SQLiteStatement = _connection.prepare(limitOffsetQuery.sql)
        limitOffsetQuery.getBindingFunction().invoke(_stmt)
        try {
          val _columnIndexOfEUid: Int = getColumnIndexOrThrow(_stmt, "eUid")
          val _columnIndexOfEUidNum: Int = getColumnIndexOrThrow(_stmt, "eUidNum")
          val _columnIndexOfEStatus: Int = getColumnIndexOrThrow(_stmt, "eStatus")
          val _columnIndexOfELastModified: Int = getColumnIndexOrThrow(_stmt, "eLastModified")
          val _columnIndexOfEStored: Int = getColumnIndexOrThrow(_stmt, "eStored")
          val _columnIndexOfEMetadata: Int = getColumnIndexOrThrow(_stmt, "eMetadata")
          val _columnIndexOfEClassUid: Int = getColumnIndexOrThrow(_stmt, "eClassUid")
          val _columnIndexOfEClassUidNum: Int = getColumnIndexOrThrow(_stmt, "eClassUidNum")
          val _columnIndexOfEPersonUid: Int = getColumnIndexOrThrow(_stmt, "ePersonUid")
          val _columnIndexOfEPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "ePersonUidNum")
          val _columnIndexOfERole: Int = getColumnIndexOrThrow(_stmt, "eRole")
          val _columnIndexOfEBeginDate: Int = getColumnIndexOrThrow(_stmt, "eBeginDate")
          val _columnIndexOfEEndDate: Int = getColumnIndexOrThrow(_stmt, "eEndDate")
          val _columnIndexOfEInviteCode: Int = getColumnIndexOrThrow(_stmt, "eInviteCode")
          val _columnIndexOfEApprovedByPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUidNum")
          val _columnIndexOfEApprovedByPersonUid: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUid")
          val _result: MutableList<EnrollmentEntity> = mutableListOf()
          while (_stmt.step()) {
            val _item: EnrollmentEntity
            val _tmpEUid: String
            _tmpEUid = _stmt.getText(_columnIndexOfEUid)
            val _tmpEUidNum: Long
            _tmpEUidNum = _stmt.getLong(_columnIndexOfEUidNum)
            val _tmpEStatus: StatusEnum
            val _tmp: Int
            _tmp = _stmt.getLong(_columnIndexOfEStatus).toInt()
            _tmpEStatus = __schoolTypeConverters.toStatusEnum(_tmp)
            val _tmpELastModified: Instant
            val _tmp_1: Long?
            if (_stmt.isNull(_columnIndexOfELastModified)) {
              _tmp_1 = null
            } else {
              _tmp_1 = _stmt.getLong(_columnIndexOfELastModified)
            }
            val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
            if (_tmp_2 == null) {
              error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
            } else {
              _tmpELastModified = _tmp_2
            }
            val _tmpEStored: Instant
            val _tmp_3: Long?
            if (_stmt.isNull(_columnIndexOfEStored)) {
              _tmp_3 = null
            } else {
              _tmp_3 = _stmt.getLong(_columnIndexOfEStored)
            }
            val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
            if (_tmp_4 == null) {
              error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
            } else {
              _tmpEStored = _tmp_4
            }
            val _tmpEMetadata: JsonObject?
            val _tmp_5: String?
            if (_stmt.isNull(_columnIndexOfEMetadata)) {
              _tmp_5 = null
            } else {
              _tmp_5 = _stmt.getText(_columnIndexOfEMetadata)
            }
            _tmpEMetadata = __schoolTypeConverters.toJsonObject(_tmp_5)
            val _tmpEClassUid: String
            _tmpEClassUid = _stmt.getText(_columnIndexOfEClassUid)
            val _tmpEClassUidNum: Long
            _tmpEClassUidNum = _stmt.getLong(_columnIndexOfEClassUidNum)
            val _tmpEPersonUid: String
            _tmpEPersonUid = _stmt.getText(_columnIndexOfEPersonUid)
            val _tmpEPersonUidNum: Long
            _tmpEPersonUidNum = _stmt.getLong(_columnIndexOfEPersonUidNum)
            val _tmpERole: EnrollmentRoleEnum
            val _tmp_6: Int
            _tmp_6 = _stmt.getLong(_columnIndexOfERole).toInt()
            _tmpERole = __schoolTypeConverters.toEnrollmentRoleEnum(_tmp_6)
            val _tmpEBeginDate: LocalDate?
            val _tmp_7: Long?
            if (_stmt.isNull(_columnIndexOfEBeginDate)) {
              _tmp_7 = null
            } else {
              _tmp_7 = _stmt.getLong(_columnIndexOfEBeginDate)
            }
            _tmpEBeginDate = __schoolTypeConverters.toLocalDate(_tmp_7)
            val _tmpEEndDate: LocalDate?
            val _tmp_8: Long?
            if (_stmt.isNull(_columnIndexOfEEndDate)) {
              _tmp_8 = null
            } else {
              _tmp_8 = _stmt.getLong(_columnIndexOfEEndDate)
            }
            _tmpEEndDate = __schoolTypeConverters.toLocalDate(_tmp_8)
            val _tmpEInviteCode: String?
            if (_stmt.isNull(_columnIndexOfEInviteCode)) {
              _tmpEInviteCode = null
            } else {
              _tmpEInviteCode = _stmt.getText(_columnIndexOfEInviteCode)
            }
            val _tmpEApprovedByPersonUidNum: Long
            _tmpEApprovedByPersonUidNum = _stmt.getLong(_columnIndexOfEApprovedByPersonUidNum)
            val _tmpEApprovedByPersonUid: String?
            if (_stmt.isNull(_columnIndexOfEApprovedByPersonUid)) {
              _tmpEApprovedByPersonUid = null
            } else {
              _tmpEApprovedByPersonUid = _stmt.getText(_columnIndexOfEApprovedByPersonUid)
            }
            _item = EnrollmentEntity(_tmpEUid,_tmpEUidNum,_tmpEStatus,_tmpELastModified,_tmpEStored,_tmpEMetadata,_tmpEClassUid,_tmpEClassUidNum,_tmpEPersonUid,_tmpEPersonUidNum,_tmpERole,_tmpEBeginDate,_tmpEEndDate,_tmpEInviteCode,_tmpEApprovedByPersonUidNum,_tmpEApprovedByPersonUid)
            _result.add(_item)
          }
          _result
        } finally {
          _stmt.close()
        }
      }
    }
  }

  public override suspend fun getLastModifiedByUidNum(uidNum: Long): Long? {
    val _sql: String = """
        |
        |        SELECT EnrollmentEntity.eLastModified
        |          FROM EnrollmentEntity
        |         WHERE EnrollmentEntity.eUidNum = ? 
        |    
        """.trimMargin()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        _stmt.bindLong(_argIndex, uidNum)
        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 findByUidNumList(uidNums: List<Long>): List<EnrollmentEntity> {
    val _stringBuilder: StringBuilder = StringBuilder()
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("        SELECT EnrollmentEntity.*")
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("          FROM EnrollmentEntity")
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("         WHERE EnrollmentEntity.eUidNum IN (")
    val _inputSize: Int = uidNums.size
    appendPlaceholders(_stringBuilder, _inputSize)
    _stringBuilder.append(") ")
    _stringBuilder.append("""
        |
        |""".trimMargin())
    _stringBuilder.append("    ")
    val _sql: String = _stringBuilder.toString()
    return performSuspending(__db, true, false) { _connection ->
      val _stmt: SQLiteStatement = _connection.prepare(_sql)
      try {
        var _argIndex: Int = 1
        for (_item: Long in uidNums) {
          _stmt.bindLong(_argIndex, _item)
          _argIndex++
        }
        val _columnIndexOfEUid: Int = getColumnIndexOrThrow(_stmt, "eUid")
        val _columnIndexOfEUidNum: Int = getColumnIndexOrThrow(_stmt, "eUidNum")
        val _columnIndexOfEStatus: Int = getColumnIndexOrThrow(_stmt, "eStatus")
        val _columnIndexOfELastModified: Int = getColumnIndexOrThrow(_stmt, "eLastModified")
        val _columnIndexOfEStored: Int = getColumnIndexOrThrow(_stmt, "eStored")
        val _columnIndexOfEMetadata: Int = getColumnIndexOrThrow(_stmt, "eMetadata")
        val _columnIndexOfEClassUid: Int = getColumnIndexOrThrow(_stmt, "eClassUid")
        val _columnIndexOfEClassUidNum: Int = getColumnIndexOrThrow(_stmt, "eClassUidNum")
        val _columnIndexOfEPersonUid: Int = getColumnIndexOrThrow(_stmt, "ePersonUid")
        val _columnIndexOfEPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "ePersonUidNum")
        val _columnIndexOfERole: Int = getColumnIndexOrThrow(_stmt, "eRole")
        val _columnIndexOfEBeginDate: Int = getColumnIndexOrThrow(_stmt, "eBeginDate")
        val _columnIndexOfEEndDate: Int = getColumnIndexOrThrow(_stmt, "eEndDate")
        val _columnIndexOfEInviteCode: Int = getColumnIndexOrThrow(_stmt, "eInviteCode")
        val _columnIndexOfEApprovedByPersonUidNum: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUidNum")
        val _columnIndexOfEApprovedByPersonUid: Int = getColumnIndexOrThrow(_stmt, "eApprovedByPersonUid")
        val _result: MutableList<EnrollmentEntity> = mutableListOf()
        while (_stmt.step()) {
          val _item_1: EnrollmentEntity
          val _tmpEUid: String
          _tmpEUid = _stmt.getText(_columnIndexOfEUid)
          val _tmpEUidNum: Long
          _tmpEUidNum = _stmt.getLong(_columnIndexOfEUidNum)
          val _tmpEStatus: StatusEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfEStatus).toInt()
          _tmpEStatus = __schoolTypeConverters.toStatusEnum(_tmp)
          val _tmpELastModified: Instant
          val _tmp_1: Long?
          if (_stmt.isNull(_columnIndexOfELastModified)) {
            _tmp_1 = null
          } else {
            _tmp_1 = _stmt.getLong(_columnIndexOfELastModified)
          }
          val _tmp_2: Instant? = __sharedConverters.toInstant(_tmp_1)
          if (_tmp_2 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpELastModified = _tmp_2
          }
          val _tmpEStored: Instant
          val _tmp_3: Long?
          if (_stmt.isNull(_columnIndexOfEStored)) {
            _tmp_3 = null
          } else {
            _tmp_3 = _stmt.getLong(_columnIndexOfEStored)
          }
          val _tmp_4: Instant? = __sharedConverters.toInstant(_tmp_3)
          if (_tmp_4 == null) {
            error("Expected NON-NULL 'kotlin.time.Instant', but it was NULL.")
          } else {
            _tmpEStored = _tmp_4
          }
          val _tmpEMetadata: JsonObject?
          val _tmp_5: String?
          if (_stmt.isNull(_columnIndexOfEMetadata)) {
            _tmp_5 = null
          } else {
            _tmp_5 = _stmt.getText(_columnIndexOfEMetadata)
          }
          _tmpEMetadata = __schoolTypeConverters.toJsonObject(_tmp_5)
          val _tmpEClassUid: String
          _tmpEClassUid = _stmt.getText(_columnIndexOfEClassUid)
          val _tmpEClassUidNum: Long
          _tmpEClassUidNum = _stmt.getLong(_columnIndexOfEClassUidNum)
          val _tmpEPersonUid: String
          _tmpEPersonUid = _stmt.getText(_columnIndexOfEPersonUid)
          val _tmpEPersonUidNum: Long
          _tmpEPersonUidNum = _stmt.getLong(_columnIndexOfEPersonUidNum)
          val _tmpERole: EnrollmentRoleEnum
          val _tmp_6: Int
          _tmp_6 = _stmt.getLong(_columnIndexOfERole).toInt()
          _tmpERole = __schoolTypeConverters.toEnrollmentRoleEnum(_tmp_6)
          val _tmpEBeginDate: LocalDate?
          val _tmp_7: Long?
          if (_stmt.isNull(_columnIndexOfEBeginDate)) {
            _tmp_7 = null
          } else {
            _tmp_7 = _stmt.getLong(_columnIndexOfEBeginDate)
          }
          _tmpEBeginDate = __schoolTypeConverters.toLocalDate(_tmp_7)
          val _tmpEEndDate: LocalDate?
          val _tmp_8: Long?
          if (_stmt.isNull(_columnIndexOfEEndDate)) {
            _tmp_8 = null
          } else {
            _tmp_8 = _stmt.getLong(_columnIndexOfEEndDate)
          }
          _tmpEEndDate = __schoolTypeConverters.toLocalDate(_tmp_8)
          val _tmpEInviteCode: String?
          if (_stmt.isNull(_columnIndexOfEInviteCode)) {
            _tmpEInviteCode = null
          } else {
            _tmpEInviteCode = _stmt.getText(_columnIndexOfEInviteCode)
          }
          val _tmpEApprovedByPersonUidNum: Long
          _tmpEApprovedByPersonUidNum = _stmt.getLong(_columnIndexOfEApprovedByPersonUidNum)
          val _tmpEApprovedByPersonUid: String?
          if (_stmt.isNull(_columnIndexOfEApprovedByPersonUid)) {
            _tmpEApprovedByPersonUid = null
          } else {
            _tmpEApprovedByPersonUid = _stmt.getText(_columnIndexOfEApprovedByPersonUid)
          }
          _item_1 = EnrollmentEntity(_tmpEUid,_tmpEUidNum,_tmpEStatus,_tmpELastModified,_tmpEStored,_tmpEMetadata,_tmpEClassUid,_tmpEClassUidNum,_tmpEPersonUid,_tmpEPersonUidNum,_tmpERole,_tmpEBeginDate,_tmpEEndDate,_tmpEInviteCode,_tmpEApprovedByPersonUidNum,_tmpEApprovedByPersonUid)
          _result.add(_item_1)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

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