package hu.bbara.purefin.core.data.room.dao

import androidx.room.Dao
import androidx.room.Query
import androidx.room.Upsert
import hu.bbara.purefin.core.data.room.entity.SeasonEntity
import java.util.UUID

@Dao
interface SeasonDao {
    @Upsert
    suspend fun upsert(season: SeasonEntity)

    @Upsert
    suspend fun upsertAll(seasons: List<SeasonEntity>)

    @Query("SELECT * FROM seasons WHERE seriesId = :seriesId")
    suspend fun getBySeriesId(seriesId: UUID): List<SeasonEntity>

    @Query("SELECT * FROM seasons WHERE id = :id")
    suspend fun getById(id: UUID): SeasonEntity?

    @Query("UPDATE seasons SET unwatchedEpisodeCount = :count WHERE id = :id")
    suspend fun updateUnwatchedCount(id: UUID, count: Int)

    @Query("DELETE FROM seasons WHERE seriesId = :seriesId")
    suspend fun deleteBySeriesId(seriesId: UUID)

    @Query("DELETE FROM seasons WHERE id = :id")
    suspend fun deleteById(id: UUID)

    @Query("SELECT COUNT(*) FROM seasons WHERE seriesId = :seriesId")
    suspend fun countBySeriesId(seriesId: UUID): Int
}
