/*
 * Book's Story — free and open-source Material You eBook reader.
 * Copyright (C) 2024-2026 Acclorite
 * SPDX-License-Identifier: GPL-3.0-only
 */

package org.dueattendant149.bookshelf.data.local.room

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import org.dueattendant149.bookshelf.data.local.dto.EbookFileEntity

@Dao
interface EbookFileDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(file: EbookFileEntity)

    @Query("SELECT * FROM ebook_file WHERE bookId = :bookId LIMIT 1")
    suspend fun getByBookId(bookId: Int): EbookFileEntity?

    @Update
    suspend fun update(file: EbookFileEntity)

    @Delete
    suspend fun delete(file: EbookFileEntity)

    @Query("DELETE FROM ebook_file WHERE bookId = :bookId")
    suspend fun deleteByBookId(bookId: Int)
}
