package cz.muni.sutralog.data

import java.time.LocalDate
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class  RockPresentableListItem(
    val id: Long = 0,
    var categoryId: Long,

    var name: String,
    var count: Int? = null,
    var locality: String = "",
    var latitude: Double? = null,
    var longitude: Double? = null,
    var from: String = "",
    var date: LocalDate? = null,
    var where: String = "",
    var description: String = "",
    var comment: String = "",
    var color: Int
): Parcelable{
    fun <T>columnContains(property: RockPresentableListItem.() -> T?, searchKey : String): Boolean{
        if(searchKey.isBlank()){
            return true
        }
        return this.property()?.toString()?.contains(searchKey.lowercase().trim()) ?: false
    }

    fun isInDate(fromDate : LocalDate?, toDate: LocalDate?) : Boolean{
        if(fromDate == null && toDate == null){
            return true
        }

        if(date == null){
            return false
        }

        if(fromDate?.isBefore(date!!.plusDays(1)) != false
                    && toDate?.isAfter(date!!.minusDays(1)) != false){
            return true
        }

        return false
    }
}