/*
 * 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.history

import org.dueattendant149.bookshelf.core.log.logE
import org.dueattendant149.bookshelf.core.log.logI
import org.dueattendant149.bookshelf.domain.model.history.History
import org.dueattendant149.bookshelf.domain.repository.HistoryRepository
import javax.inject.Inject

private const val TAG = "AddHistory"

class AddHistoryUseCase @Inject constructor(
    private val historyRepository: HistoryRepository
) {

    suspend operator fun invoke(history: History) {
        logI(TAG, "Inserting history for [${history.book.id}].")

        historyRepository.addHistory(history = history).fold(
            onSuccess = {
                logI(TAG, "Successfully inserted history for [${history.book.id}].")
            },
            onFailure = {
                logE(
                    TAG,
                    "Could not insert history for [${history.book.id}] with error: ${it.message}"
                )
            }
        )
    }
}