package app.closer.data.local

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import app.closer.data.local.entity.DatePlanEntity

@Dao
interface DatePlanDao {
    @Query("SELECT * FROM date_plans WHERE id = :id LIMIT 1")
    suspend fun getById(id: String): DatePlanEntity?

    @Query("SELECT * FROM date_plans WHERE couple_id = :coupleId ORDER BY scheduled_date ASC")
    suspend fun getByCoupleId(coupleId: String): List<DatePlanEntity>

    @Query("SELECT * FROM date_plans WHERE couple_id = :coupleId AND status = :status ORDER BY scheduled_date ASC")
    suspend fun getByCoupleIdAndStatus(coupleId: String, status: String): List<DatePlanEntity>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(plan: DatePlanEntity)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertAll(plans: List<DatePlanEntity>)

    @Delete
    suspend fun delete(plan: DatePlanEntity)

    @Query("UPDATE date_plans SET id = :newId, status = :status, updated_at = :updatedAt WHERE id = :oldId")
    suspend fun updateFirestoreId(oldId: String, newId: String, status: String = "draft", updatedAt: Long = System.currentTimeMillis())
}
