package com.github.nullptroma.wallenc.ui.resources

import com.github.nullptroma.wallenc.domain.tasks.TaskProgressLabel
import com.github.nullptroma.wallenc.domain.tasks.VaultTaskStep
import com.github.nullptroma.wallenc.ui.R

fun TaskProgressLabel.resolve(resolver: UiStringResolver): String = when (this) {
    TaskProgressLabel.SyncNoGroups -> resolver(R.string.sync_progress_no_groups)
    TaskProgressLabel.SyncStarted -> resolver(R.string.sync_progress_started)
    TaskProgressLabel.SyncCompleted -> resolver(R.string.sync_progress_completed)
    is TaskProgressLabel.SyncPreparing ->
        resolver.plurals(R.plurals.sync_progress_preparing, groupCount, groupCount)

    is TaskProgressLabel.SyncGroupPreparing -> resolver(R.string.sync_progress_group_preparing, groupId)
    is TaskProgressLabel.SyncGroupNotFound -> resolver(R.string.sync_progress_group_not_found, groupId)
    is TaskProgressLabel.SyncGroupSkippedTooFewStorages ->
        resolver(R.string.sync_progress_group_skipped_few_storages, groupId)
    is TaskProgressLabel.SyncGroupSkippedIncompatibleEncryption ->
        resolver(R.string.sync_progress_group_skipped_incompatible, groupId, count)
    is TaskProgressLabel.SyncGroupAcquiringLocks ->
        resolver(R.string.sync_progress_group_acquiring_locks, groupId)
    is TaskProgressLabel.SyncGroupLockProgress ->
        resolver(R.string.sync_progress_group_lock, groupId, current, total)
    is TaskProgressLabel.SyncGroupLockFailed ->
        resolver(R.string.sync_progress_group_lock_failed, groupId)
    is TaskProgressLabel.SyncGroupReadingJournals ->
        resolver(R.string.sync_progress_group_reading_journals, groupId)
    is TaskProgressLabel.SyncGroupCancelled ->
        resolver(R.string.sync_progress_group_cancelled, groupId)
    is TaskProgressLabel.SyncGroupJournalProgress ->
        resolver(R.string.sync_progress_group_journal, groupId, current, total)
    is TaskProgressLabel.SyncGroupNoJournalEntries ->
        resolver(R.string.sync_progress_group_no_entries, groupId)
    is TaskProgressLabel.SyncGroupProcessingEntries ->
        resolver.plurals(R.plurals.sync_progress_group_processing, count, groupId, count)
    is TaskProgressLabel.SyncGroupEntryProgress ->
        resolver(R.string.sync_progress_group_entry, groupId, current, total)
    is TaskProgressLabel.SyncGroupCompleted ->
        resolver(R.string.sync_progress_group_completed, groupId)
    is TaskProgressLabel.SyncGroupEntriesFailed ->
        resolver.plurals(R.plurals.sync_progress_group_entries_failed, failedCount, groupId, failedCount)
    is TaskProgressLabel.SyncGroupRenewingLocks ->
        resolver(R.string.sync_progress_group_renewing_locks, groupId)
    is TaskProgressLabel.SyncGroupLockRenewalFailed ->
        resolver(R.string.sync_progress_group_lock_renewal_failed, groupId)

    is TaskProgressLabel.ClearContentProgress ->
        resolver(R.string.task_progress_clear_content, done, total)

    is TaskProgressLabel.VaultTask -> when (step) {
        VaultTaskStep.DumpStorageLog -> resolver(R.string.task_progress_dump_storage_log)
        VaultTaskStep.CreateStorage -> resolver(R.string.task_progress_create_storage)
        VaultTaskStep.EnableEncryption -> resolver(R.string.task_progress_enable_encryption)
        VaultTaskStep.DecryptRunning -> resolver(R.string.task_progress_decrypt_running)
        VaultTaskStep.CloseStorage -> resolver(R.string.task_progress_close_storage)
        VaultTaskStep.DisableEncryption -> resolver(R.string.task_progress_disable_encryption)
        VaultTaskStep.RenameStorage -> resolver(R.string.task_progress_rename_storage)
        VaultTaskStep.RemoveStorage -> resolver(R.string.task_progress_remove_storage)
        VaultTaskStep.ClearSyncLock -> resolver(R.string.task_progress_clear_sync_lock)
        VaultTaskStep.AddRemoteVault -> resolver(R.string.task_progress_add_remote_vault)
        VaultTaskStep.RemoveRemoteVault -> resolver(R.string.task_progress_remove_remote_vault)
        VaultTaskStep.RetryRemoteVault -> resolver(R.string.task_progress_retry_remote_vault)
        VaultTaskStep.RescanVaultStorages -> resolver(R.string.task_progress_rescan_vault_storages)
        VaultTaskStep.Save2FaToken -> resolver(R.string.task_progress_save_2fa_token)
        VaultTaskStep.Delete2FaToken -> resolver(R.string.task_progress_delete_2fa_token)
        VaultTaskStep.SaveTextSecret -> resolver(R.string.task_progress_save_text_secret)
        VaultTaskStep.DeleteTextSecret -> resolver(R.string.task_progress_delete_text_secret)
    }

    is TaskProgressLabel.TestElapsed ->
        resolver(R.string.task_pipeline_test_elapsed, elapsedSec, totalSec)
}
