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

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

private const val TAG = "AddCategory"

class AddCategoryUseCase @Inject constructor(
    private val categoryRepository: CategoryRepository
) {

    suspend operator fun invoke(title: String) {
        logI(TAG, "Inserting [${title}] category.")

        categoryRepository.addCategory(Category(title = title)).fold(
            onSuccess = {
                logI(TAG, "Successfully inserted [${title}] category.")
            },
            onFailure = {
                logE(TAG, "Could not insert [${title}] category with error: ${it.message}")
            }
        )
    }
}