package com.isidroid.job.data.source.local

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.isidroid.job.constant.JobStatus
import com.isidroid.job.model.PrintJob

@Dao
interface JobDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg printJob: PrintJob)

    @Delete
    fun delete(vararg printJob: PrintJob)

    @Query("SELECT * FROM PrintJob " +
            "WHERE (:spotId IS NULL OR spotId = :spotId) " +
            "AND (:status IS NULL OR status = :status) " +
            "AND (:ids IS NULL OR id IN (:ids))" +
            "ORDER BY createdAt DESC")
    fun find(
        spotId: String? = null,
        @JobStatus status: Int? = null,
        ids: List<String>? = null
    ): List<PrintJob>

    @Query("UPDATE PrintJob SET status = :status WHERE id IN (:ids)")
    fun updateJobStatus(status: Int, vararg ids: String)
}