package com.placeholder.sherpai2.data.local.entity

import androidx.room.Entity
import androidx.room.Index
import androidx.room.PrimaryKey
import java.util.UUID

/**
 * CollectionEntity - User-created photo collections
 *
 * Types:
 * - SMART: Dynamic collection based on filters (re-evaluated)
 * - STATIC: Fixed snapshot of photos
 * - FAVORITE: Special favorites collection
 */
@Entity(
    tableName = "collections",
    indices = [
        Index(value = ["name"]),
        Index(value = ["type"]),
        Index(value = ["createdAt"])
    ]
)
data class CollectionEntity(
    @PrimaryKey
    val collectionId: String,

    val name: String,
    val description: String?,

    /**
     * Cover image (auto-selected or user-chosen)
     */
    val coverImageUri: String?,

    /**
     * SMART | STATIC | FAVORITE
     */
    val type: String,

    /**
     * Cached photo count for performance
     */
    val photoCount: Int,

    val createdAt: Long,
    val updatedAt: Long,

    /**
     * Pinned to top of collections list
     */
    val isPinned: Boolean
) {
    companion object {
        fun createSmart(
            name: String,
            description: String? = null
        ): CollectionEntity {
            val now = System.currentTimeMillis()
            return CollectionEntity(
                collectionId = UUID.randomUUID().toString(),
                name = name,
                description = description,
                coverImageUri = null,
                type = "SMART",
                photoCount = 0,
                createdAt = now,
                updatedAt = now,
                isPinned = false
            )
        }

        fun createStatic(
            name: String,
            description: String? = null,
            photoCount: Int = 0
        ): CollectionEntity {
            val now = System.currentTimeMillis()
            return CollectionEntity(
                collectionId = UUID.randomUUID().toString(),
                name = name,
                description = description,
                coverImageUri = null,
                type = "STATIC",
                photoCount = photoCount,
                createdAt = now,
                updatedAt = now,
                isPinned = false
            )
        }

        fun createFavorite(): CollectionEntity {
            val now = System.currentTimeMillis()
            return CollectionEntity(
                collectionId = "favorites",
                name = "Favorites",
                description = "Your favorite photos",
                coverImageUri = null,
                type = "FAVORITE",
                photoCount = 0,
                createdAt = now,
                updatedAt = now,
                isPinned = true
            )
        }
    }
}