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

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index

/**
 * CollectionImageEntity - Join table linking collections to images
 *
 * Supports:
 * - Custom sort order
 * - Timestamp when added
 */
@Entity(
    tableName = "collection_images",
    primaryKeys = ["collectionId", "imageId"],
    foreignKeys = [
        ForeignKey(
            entity = CollectionEntity::class,
            parentColumns = ["collectionId"],
            childColumns = ["collectionId"],
            onDelete = ForeignKey.CASCADE
        ),
        ForeignKey(
            entity = ImageEntity::class,
            parentColumns = ["imageId"],
            childColumns = ["imageId"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [
        Index("collectionId"),
        Index("imageId"),
        Index("addedAt")
    ]
)
data class CollectionImageEntity(
    val collectionId: String,
    val imageId: String,

    /**
     * When this image was added to the collection
     */
    val addedAt: Long,

    /**
     * Custom sort order (lower = earlier)
     */
    val sortOrder: Int
)