package com.gestoreasy.database.dao

import androidx.room.*
import com.gestoreasy.database.entities.Goal
import kotlinx.coroutines.flow.Flow

@Dao
interface GoalDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertOrUpdate(goal: Goal)
    
    @Query("SELECT * FROM goals ORDER BY data_inicio DESC")
    suspend fun getAll(): List<Goal>
    
    @Query("SELECT * FROM goals WHERE ativo = 1 ORDER BY data_inicio DESC")
    suspend fun getActive(): List<Goal>
    
    @Query("SELECT * FROM goals WHERE tipo = :tipo AND ativo = 1 ORDER BY data_inicio DESC")
    suspend fun getByType(tipo: String): List<Goal>
    
    @Query("SELECT * FROM goals WHERE ativo = 1 ORDER BY data_inicio DESC")
    fun getAllFlow(): Flow<List<Goal>>
}

