package com.github.nullptroma.wallenc.domain.vault.storages.yandex

import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepository
import com.github.nullptroma.wallenc.domain.vault.storages.common.BaseStorage
import com.github.nullptroma.wallenc.domain.vault.storages.local.LocalStorage
import com.github.nullptroma.wallenc.domain.interfaces.IStorageAccessor
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
import java.util.UUID

class YandexStorage(
    uuid: UUID,
    private val repo: YandexDiskRepository,
    vaultAvailability: StateFlow<Boolean>,
    private val ioDispatcher: CoroutineDispatcher,
    accessorScope: CoroutineScope,
    private val reportAuthFailure: () -> Unit,
) : BaseStorage(
    uuid = uuid,
    ioDispatcher = ioDispatcher,
    metaInfoFilePostfix = LocalStorage.STORAGE_INFO_FILE_POSTFIX,
) {

    private val _accessor = YandexStorageAccessor(
        storageUuid = uuid,
        repo = repo,
        ioDispatcher = ioDispatcher,
        vaultAvailability = vaultAvailability,
        accessorScope = accessorScope,
        reportAuthFailure = reportAuthFailure,
    )
    override val accessor: IStorageAccessor = _accessor
    override val isVirtualStorage: Boolean = false

    override suspend fun init() {
        _accessor.init()
        super.init()
    }
}
