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

import org.dueattendant149.bookshelf.core.log.logE
import org.dueattendant149.bookshelf.core.log.logI
import org.dueattendant149.bookshelf.domain.repository.PermissionRepository
import javax.inject.Inject

private const val TAG = "ReleaseUriPermission"

class ReleasePersistableUriPermissionUseCase @Inject constructor(
    private val permissionRepository: PermissionRepository
) {

    suspend operator fun invoke(uri: String) {
        logI(TAG, "Releasing persistable URI permission from \"$uri\".")

        permissionRepository.releasePersistableUriPermission(uri).fold(
            onSuccess = {
                logI(TAG, "Successfully released persistable URI permission from \"$uri\".")
            },
            onFailure = {
                logE(
                    TAG,
                    "Could not release persistable URI permission from \"$uri\" with error: ${it.message}."
                )
            }
        )
    }
}