package com.rssuper.models

import android.os.Parcelable
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.rssuper.converters.DateConverter
import com.rssuper.converters.StringListConverter
import kotlinx.parcelize.Parcelize
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import java.util.Date

@JsonClass(generateAdapter = true)
@Parcelize
@TypeConverters(DateConverter::class, StringListConverter::class)
@Entity(tableName = "search_filters")
data class SearchFilters(
    @PrimaryKey
    val id: String = "default",
    
    @Json(name = "dateFrom")
    val dateFrom: Date? = null,
    
    @Json(name = "dateTo")
    val dateTo: Date? = null,
    
    @Json(name = "feedIds")
    val feedIds: List<String>? = null,
    
    @Json(name = "authors")
    val authors: List<String>? = null,
    
    @Json(name = "contentType")
    val contentType: ContentType? = null,
    
    @Json(name = "sortOption")
    val sortOption: SearchSortOption = SearchSortOption.RELEVANCE
) : Parcelable

sealed class ContentType(val value: String) {
    @Json(name = "article")
    data object ARTICLE : ContentType("article")
    
    @Json(name = "audio")
    data object AUDIO : ContentType("audio")
    
    @Json(name = "video")
    data object VIDEO : ContentType("video")
}

sealed class SearchSortOption(val value: String) {
    @Json(name = "relevance")
    data object RELEVANCE : SearchSortOption("relevance")
    
    @Json(name = "date_desc")
    data object DATE_DESC : SearchSortOption("date_desc")
    
    @Json(name = "date_asc")
    data object DATE_ASC : SearchSortOption("date_asc")
    
    @Json(name = "title_asc")
    data object TITLE_ASC : SearchSortOption("title_asc")
    
    @Json(name = "title_desc")
    data object TITLE_DESC : SearchSortOption("title_desc")
    
    @Json(name = "feed_asc")
    data object FEED_ASC : SearchSortOption("feed_asc")
    
    @Json(name = "feed_desc")
    data object FEED_DESC : SearchSortOption("feed_desc")
}
