/*
 * 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.domain.use_case.book

import org.dueattendant149.bookshelf.core.log.logE
import org.dueattendant149.bookshelf.core.log.logI
import org.dueattendant149.bookshelf.domain.model.library.Book
import org.dueattendant149.bookshelf.domain.repository.BookRepository
import javax.inject.Inject

private const val TAG = "UpdateBook"

class UpdateBookUseCase @Inject constructor(
    private val bookRepository: BookRepository
) {

    suspend operator fun invoke(book: Book) {
        logI(TAG, "Updating [${book.title}].")

        bookRepository.updateBook(book).fold(
            onSuccess = {
                logI(TAG, "Successfully updated [${book.title}].")
            },
            onFailure = {
                logE(TAG, "Could not update [${book.title}] with error: ${it.message}")
            }
        )
    }
}