package com.rosetta.messenger.ui.chats.attach

import android.net.Uri

const val ALL_MEDIA_ALBUM_ID = 0L

/**
 * Media item from gallery
 */
data class MediaItem(
    val id: Long,
    val uri: Uri,
    val mimeType: String,
    val duration: Long = 0, // For videos, in milliseconds
    val dateModified: Long = 0,
    val bucketId: Long = 0,
    val bucketName: String = ""
) {
    val isVideo: Boolean get() = mimeType.startsWith("video/")
}

data class MediaAlbum(
    val id: Long,
    val name: String,
    val items: List<MediaItem>,
    val isAllMedia: Boolean = false
)

data class MediaPickerData(
    val items: List<MediaItem>,
    val albums: List<MediaAlbum>
)

/**
 * Tab types for the attach alert
 */
enum class AttachAlertTab {
    PHOTO,
    FILE,
    AVATAR
}

/**
 * UI state for the attach alert, managed by AttachAlertViewModel
 */
data class AttachAlertUiState(
    val currentTab: AttachAlertTab = AttachAlertTab.PHOTO,
    val mediaItems: List<MediaItem> = emptyList(),
    val albums: List<MediaAlbum> = emptyList(),
    val selectedAlbumId: Long = ALL_MEDIA_ALBUM_ID,
    val selectedItemOrder: List<Long> = emptyList(),
    val isLoading: Boolean = true,
    val hasPermission: Boolean = false,
    val captionText: String = "",
    val editingItem: MediaItem? = null
) {
    val selectedCount: Int get() = selectedItemOrder.size

    val visibleAlbum: MediaAlbum?
        get() = albums.firstOrNull { it.id == selectedAlbumId } ?: albums.firstOrNull()

    val visibleMediaItems: List<MediaItem>
        get() = visibleAlbum?.items ?: mediaItems

    val canSwitchAlbums: Boolean get() = albums.size > 1
}

// ThumbnailPosition is defined in com.rosetta.messenger.ui.chats.components.ImageEditorScreen
// and reused via import. No duplicate needed here.
