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

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

/**
 * CollectionFilterEntity - Filters for SMART collections
 *
 * Filter Types:
 * - PERSON_INCLUDE: Person must be in photo
 * - PERSON_EXCLUDE: Person must NOT be in photo
 * - TAG_INCLUDE: Tag must be present
 * - TAG_EXCLUDE: Tag must NOT be present
 * - DATE_RANGE: Date filter (TODAY, THIS_WEEK, etc)
 */
@Entity(
    tableName = "collection_filters",
    foreignKeys = [
        ForeignKey(
            entity = CollectionEntity::class,
            parentColumns = ["collectionId"],
            childColumns = ["collectionId"],
            onDelete = ForeignKey.CASCADE
        )
    ],
    indices = [
        Index("collectionId"),
        Index("filterType")
    ]
)
data class CollectionFilterEntity(
    @PrimaryKey
    val filterId: String,

    val collectionId: String,

    /**
     * PERSON_INCLUDE | PERSON_EXCLUDE | TAG_INCLUDE | TAG_EXCLUDE | DATE_RANGE
     */
    val filterType: String,

    /**
     * The filter value:
     * - For PERSON_*: personId
     * - For TAG_*: tag value
     * - For DATE_RANGE: "TODAY", "THIS_WEEK", etc
     */
    val filterValue: String,

    val createdAt: Long
) {
    companion object {
        fun create(
            collectionId: String,
            filterType: String,
            filterValue: String
        ): CollectionFilterEntity {
            return CollectionFilterEntity(
                filterId = UUID.randomUUID().toString(),
                collectionId = collectionId,
                filterType = filterType,
                filterValue = filterValue,
                createdAt = System.currentTimeMillis()
            )
        }
    }
}