package de.kif.common.model

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

@Serializable
data class WorkGroup(
    override val id: Long? = null,
    val name: String = "",
    val description: String = "",
    val interested: Int = 0,
    val track: Track? = null,
    val projector: Boolean = false,
    val resolution: Boolean = false,
    val internet: Boolean = false,
    val whiteboard: Boolean = false,
    val blackboard: Boolean = false,
    val accessible: Boolean = false,
    val length: Int = 0,
    val language: Language = Language.GERMAN,
    val leader: List<String> = emptyList(),
    val constraints: List<WorkGroupConstraint> = emptyList(),
    override val createdAt: Long = 0,
    override val updateAt: Long = 0
) : Model {

    override fun createSearch() = SearchElement(
        mapOf(
            "name" to name,
            "track" to (track?.name ?: ""),
            "language" to language.localeName
        ), mapOf(
            "projector" to projector,
            "resolution" to resolution
        ), mapOf(
            "interested" to interested.toDouble(),
            "length" to length.toDouble()
        )
    )

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

        other as WorkGroup

        if (id != other.id) return false
        if (name != other.name) return false
        if (description != other.description) return false
        if (interested != other.interested) return false
        if (track != other.track) return false
        if (projector != other.projector) return false
        if (resolution != other.resolution) 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 (length != other.length) return false
        if (language != other.language) return false
        if (leader != other.leader) return false
        if (constraints != other.constraints) return false

        return true
    }

    fun equalsIgnoreId(other: WorkGroup): 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 + description.hashCode()
        result = 31 * result + interested
        result = 31 * result + (track?.hashCode() ?: 0)
        result = 31 * result + projector.hashCode()
        result = 31 * result + resolution.hashCode()
        result = 31 * result + internet.hashCode()
        result = 31 * result + whiteboard.hashCode()
        result = 31 * result + blackboard.hashCode()
        result = 31 * result + accessible.hashCode()
        result = 31 * result + length
        result = 31 * result + language.hashCode()
        result = 31 * result + leader.hashCode()
        result = 31 * result + constraints.hashCode()
        return result
    }
}
