package com.manalejandro.odb2bluetooth.data.database.dao

import androidx.room.Dao
import androidx.room.Query
import com.manalejandro.odb2bluetooth.data.database.entities.DtcCode
import kotlinx.coroutines.flow.Flow

/**
 * Data Access Object for DTC (Diagnostic Trouble Codes) queries
 */
@Dao
interface DtcCodeDao {

    @Query("SELECT * FROM dtc_codes ORDER BY code")
    fun getAllDtcCodes(): Flow<List<DtcCode>>

    @Query("SELECT * FROM dtc_codes WHERE code = :code")
    suspend fun getDtcCodeByCode(code: String): DtcCode?

    @Query("""
        SELECT * FROM dtc_codes 
        WHERE code LIKE '%' || :query || '%' 
           OR description LIKE '%' || :query || '%'
        ORDER BY code
    """)
    fun searchDtcCodes(query: String): Flow<List<DtcCode>>
}

