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

import androidx.room.EntityInsertAdapter
import androidx.room.RoomDatabase
import androidx.room.util.getColumnIndexOrThrow
import androidx.room.util.performSuspending
import androidx.sqlite.SQLiteStatement
import javax.`annotation`.processing.Generated
import kotlin.Int
import kotlin.Long
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.MutableList
import kotlin.collections.mutableListOf
import kotlin.reflect.KClass
import world.respect.datalayer.db.school.SchoolTypeConverters
import world.respect.datalayer.db.school.xapi.entities.XapiStatementContextActivityJoin
import world.respect.datalayer.db.school.xapi.entities.XapiStatementContextActivityJoinTypeEnum

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

  private val __insertAdapterOfXapiStatementContextActivityJoin:
      EntityInsertAdapter<XapiStatementContextActivityJoin>

  private val __schoolTypeConverters: SchoolTypeConverters = SchoolTypeConverters()
  init {
    this.__db = __db
    this.__insertAdapterOfXapiStatementContextActivityJoin = object : EntityInsertAdapter<XapiStatementContextActivityJoin>() {
      protected override fun createQuery(): String = "INSERT OR IGNORE INTO `XapiStatementContextActivityJoin` (`scajUid`,`scajFromStatementIdHi`,`scajFromStatementIdLo`,`scajContextType`,`scajToActivityUid`,`scajToActivityId`) VALUES (nullif(?, 0),?,?,?,?,?)"

      protected override fun bind(statement: SQLiteStatement, entity: XapiStatementContextActivityJoin) {
        statement.bindLong(1, entity.scajUid)
        statement.bindLong(2, entity.scajFromStatementIdHi)
        statement.bindLong(3, entity.scajFromStatementIdLo)
        val _tmp: Int = __schoolTypeConverters.fromStatementContextActivityJoinTypeEnum(entity.scajContextType)
        statement.bindLong(4, _tmp.toLong())
        statement.bindLong(5, entity.scajToActivityUid)
        statement.bindText(6, entity.scajToActivityId)
      }
    }
  }

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

  public override suspend fun findAllByStatementIds(
    statementIdHi: Long,
    statementIdLo: Long,
    statementIdHi2: Long,
    statementIdLo2: Long,
  ): List<XapiStatementContextActivityJoin> {
    val _sql: String = """
        |
        |        SELECT XapiStatementContextActivityJoin.*
        |          FROM XapiStatementContextActivityJoin
        |         WHERE (      XapiStatementContextActivityJoin.scajFromStatementIdHi = ?
        |                  AND XapiStatementContextActivityJoin.scajFromStatementIdLo = ?)
        |            OR (     (? != 0 AND ? != 0) 
        |                 AND XapiStatementContextActivityJoin.scajFromStatementIdHi = ?
        |                 AND XapiStatementContextActivityJoin.scajFromStatementIdLo = ?)
        |    
        """.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)
        _argIndex = 3
        _stmt.bindLong(_argIndex, statementIdHi2)
        _argIndex = 4
        _stmt.bindLong(_argIndex, statementIdLo2)
        _argIndex = 5
        _stmt.bindLong(_argIndex, statementIdHi2)
        _argIndex = 6
        _stmt.bindLong(_argIndex, statementIdLo2)
        val _columnIndexOfScajUid: Int = getColumnIndexOrThrow(_stmt, "scajUid")
        val _columnIndexOfScajFromStatementIdHi: Int = getColumnIndexOrThrow(_stmt, "scajFromStatementIdHi")
        val _columnIndexOfScajFromStatementIdLo: Int = getColumnIndexOrThrow(_stmt, "scajFromStatementIdLo")
        val _columnIndexOfScajContextType: Int = getColumnIndexOrThrow(_stmt, "scajContextType")
        val _columnIndexOfScajToActivityUid: Int = getColumnIndexOrThrow(_stmt, "scajToActivityUid")
        val _columnIndexOfScajToActivityId: Int = getColumnIndexOrThrow(_stmt, "scajToActivityId")
        val _result: MutableList<XapiStatementContextActivityJoin> = mutableListOf()
        while (_stmt.step()) {
          val _item: XapiStatementContextActivityJoin
          val _tmpScajUid: Long
          _tmpScajUid = _stmt.getLong(_columnIndexOfScajUid)
          val _tmpScajFromStatementIdHi: Long
          _tmpScajFromStatementIdHi = _stmt.getLong(_columnIndexOfScajFromStatementIdHi)
          val _tmpScajFromStatementIdLo: Long
          _tmpScajFromStatementIdLo = _stmt.getLong(_columnIndexOfScajFromStatementIdLo)
          val _tmpScajContextType: XapiStatementContextActivityJoinTypeEnum
          val _tmp: Int
          _tmp = _stmt.getLong(_columnIndexOfScajContextType).toInt()
          _tmpScajContextType = __schoolTypeConverters.toStatementContextActivityJoinTypeEnum(_tmp)
          val _tmpScajToActivityUid: Long
          _tmpScajToActivityUid = _stmt.getLong(_columnIndexOfScajToActivityUid)
          val _tmpScajToActivityId: String
          _tmpScajToActivityId = _stmt.getText(_columnIndexOfScajToActivityId)
          _item = XapiStatementContextActivityJoin(_tmpScajUid,_tmpScajFromStatementIdHi,_tmpScajFromStatementIdLo,_tmpScajContextType,_tmpScajToActivityUid,_tmpScajToActivityId)
          _result.add(_item)
        }
        _result
      } finally {
        _stmt.close()
      }
    }
  }

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