package de.kif.common.model

import de.kif.common.SearchElement
import kotlinx.serialization.Serializable

@Serializable
data class Room(
    override val id: Long? = null,
    val name: String = "",
    val places: Int = 0,
    val projector: Boolean = false,
    val internet: Boolean = false,
    val whiteboard: Boolean = false,
    val blackboard: Boolean = false,
    val accessible: Boolean = false,
    val pool: Boolean = false,
    val blocked : List<RoomBlock> = emptyList(),
    override val createdAt: Long = 0,
    override val updateAt: Long = 0
) : Model {

    override fun createSearch() = SearchElement(
        mapOf(
            "name" to name
        ), mapOf(
            "projector" to projector,
            "internet" to internet,
            "whiteboard" to whiteboard,
            "blackboard" to blackboard,
            "accessible" to accessible,
            "pool" to pool
        ), mapOf(
            "places" to places.toDouble()
        )
    )

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (other == null || this::class != other::class) return false

        other as Room

        if (id != other.id) return false
        if (name != other.name) return false
        if (places != other.places) return false
        if (projector != other.projector) return false
        if (internet != other.internet) return false
        if (whiteboard != other.whiteboard) return false
        if (blackboard != other.blackboard) return false
        if (accessible != other.accessible) return false
        if (pool != other.pool) return false
        if (blocked != other.blocked) return false

        return true
    }

    fun equalsIgnoreId(other: Room): Boolean = copy(id = null) == other.copy(id = null)

    override fun hashCode(): Int {
        var result = id?.hashCode() ?: 0
        result = 31 * result + name.hashCode()
        result = 31 * result + places
        result = 31 * result + projector.hashCode()
        result = 31 * result + internet.hashCode()
        result = 31 * result + whiteboard.hashCode()
        result = 31 * result + blackboard.hashCode()
        result = 31 * result + accessible.hashCode()
        result = 31 * result + pool.hashCode()
        result = 31 * result + blocked.hashCode()
        return result
    }
}
