/*
 * 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.logI
import org.dueattendant149.bookshelf.domain.model.library.Category
import org.dueattendant149.bookshelf.domain.repository.CategoryRepository
import javax.inject.Inject

private const val TAG = "UpdateCategoryOrder"

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

    suspend operator fun invoke(categories: List<Category>) {
        logI(TAG, "Updating order of [${categories.size}] categories.")

        categoryRepository.updateOrder(categories).fold(
            onSuccess = {
                logI(TAG, "Successfully updated order of [${categories.size}] categories.")
            },
            onFailure = {
                logI(
                    TAG,
                    "Could not update order of [${categories.size}] categories with error: ${it.message}"
                )
            }
        )
    }
}