package ru.forbion.f7cloud.feature.files

enum class FilesBrowseMode {
    AllFiles,
    Personal,
    Recent,
    Favorites,
}

enum class FilesSortColumn {
    Name,
    Type,
    Modified,
}

enum class FilesSortDirection {
    Asc,
    Desc,
}

data class FilesUserConfig(
    val sortFavoritesFirst: Boolean = true,
    val sortFoldersFirst: Boolean = true,
    val folderTree: Boolean = true,
    val defaultView: String = "files",
    val showHidden: Boolean = false,
    val showMimeColumn: Boolean = false,
    val showExtensions: Boolean = true,
    val cropImagePreviews: Boolean = true,
)

data class FilesStorageStats(
    val usedBytes: Long = 0L,
    val totalBytes: Long = 0L,
    val usedLabel: String = "",
)

data class FilesFolderTreeNode(
    val id: Long,
    val basename: String,
    val displayName: String,
    val path: String,
    val children: List<FilesFolderTreeNode> = emptyList(),
)

data class FilesSearchHit(
    val name: String,
    val path: String,
    val isDirectory: Boolean,
    val fileId: Long? = null,
)

enum class FileContextAction {
    Favorite,
    Details,
    Sharing,
    Tags,
    Rename,
    MoveCopy,
    Reminder,
    OpenLocally,
    Download,
    Archive,
    Delete,
}

enum class FileDetailsTab {
    Sharing,
    Events,
}

data class FileContextMenuEntry(
    val action: FileContextAction,
    val label: String,
    val iconPath: String,
    val showChevron: Boolean = false,
    val destructive: Boolean = false,
)

data class FileShareEntry(
    val id: Long,
    val shareType: Int,
    val label: String,
    val permissionsLabel: String,
    val shareWith: String = "",
)

data class FileActivityEntry(
    val id: Long,
    val author: String,
    val message: String,
    val timestamp: Long,
)

data class FileDetailsData(
    val shares: List<FileShareEntry> = emptyList(),
    val activities: List<FileActivityEntry> = emptyList(),
    val error: String? = null,
)

fun buildFileContextMenu(item: FileItem): List<FileContextMenuEntry> = buildList {
    add(
        FileContextMenuEntry(
            action = FileContextAction.Favorite,
            label = if (item.favorite) "Удалить из избранного" else "Добавить в избранное",
            iconPath = if (item.favorite) "files/star-green-full.svg" else "files/star-gray.svg",
        ),
    )
    add(FileContextMenuEntry(FileContextAction.Details, "Подробно", "files/info-icon-black.svg"))
    add(FileContextMenuEntry(FileContextAction.Sharing, "Варианты обмена", "files/button-shared-for-files.svg"))
    add(FileContextMenuEntry(FileContextAction.Tags, "Управление метками", "files/tags-gray.svg"))
    add(FileContextMenuEntry(FileContextAction.Rename, "Переименовать", "files/rename-pencil-gray.svg"))
    add(FileContextMenuEntry(FileContextAction.MoveCopy, "Переместить или копировать", "files/copy-move-gray.svg"))
    add(
        FileContextMenuEntry(
            action = FileContextAction.Reminder,
            label = "Установить напоминание",
            iconPath = "files/grid-files-gray.svg",
            showChevron = true,
        ),
    )
    if (!item.isDirectory) {
        add(FileContextMenuEntry(FileContextAction.OpenLocally, "Открыть локально", "files/local-edit-black.svg"))
        add(FileContextMenuEntry(FileContextAction.Download, "Скачать", "files/download-icon-gray.svg"))
    }
    add(
        FileContextMenuEntry(
            action = FileContextAction.Archive,
            label = "Архивировать в...",
            iconPath = "files/folder-gray.svg",
            showChevron = true,
        ),
    )
    add(
        FileContextMenuEntry(
            action = FileContextAction.Delete,
            label = if (item.isDirectory) "Удалить папку" else "Удалить файл",
            iconPath = "files/trash-gray.svg",
            destructive = true,
        ),
    )
}

enum class FilesBulkAction {
    Favorite,
    Download,
    Delete,
}
