/*
 * 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 = "GetCategories"

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

    suspend operator fun invoke(): List<Category> {
        logI(TAG, "Getting all categories.")

        return categoryRepository.getCategories().fold(
            onSuccess = {
                logI(TAG, "Successfully got [${it.size}] categories.")
                it
            },
            onFailure = {
                logE(TAG, "Could not get categories with error: ${it.message}")
                emptyList()
            }
        )
    }
}