package com.atridad.openclimb.data.database.dao

import androidx.room.*
import com.atridad.openclimb.data.model.ClimbType
import com.atridad.openclimb.data.model.Gym
import kotlinx.coroutines.flow.Flow

@Dao
interface GymDao {
    
    @Query("SELECT * FROM gyms ORDER BY name ASC")
    fun getAllGyms(): Flow<List<Gym>>
    
    @Query("SELECT * FROM gyms WHERE id = :id")
    suspend fun getGymById(id: String): Gym?
    
    @Query("SELECT * FROM gyms WHERE :climbType IN (supportedClimbTypes)")
    fun getGymsByClimbType(climbType: ClimbType): Flow<List<Gym>>
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertGym(gym: Gym)
    
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertGyms(gyms: List<Gym>)
    
    @Update
    suspend fun updateGym(gym: Gym)
    
    @Delete
    suspend fun deleteGym(gym: Gym)
    
    @Query("DELETE FROM gyms WHERE id = :id")
    suspend fun deleteGymById(id: String)
    
    @Query("SELECT COUNT(*) FROM gyms")
    suspend fun getGymsCount(): Int
    
    @Query("SELECT * FROM gyms WHERE name LIKE '%' || :searchQuery || '%' OR location LIKE '%' || :searchQuery || '%'")
    fun searchGyms(searchQuery: String): Flow<List<Gym>>
}
