package de.kif.common.model

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

@Serializable
data class User(
    override val id: Long?,
    val username: String,
    val password: String,
    val permissions: Set<Permission>,
    override val createdAt: Long = 0,
    override val updateAt: Long = 0
) : Model {

    fun checkPermission(permission: Permission): Boolean {
        return permission in permissions || Permission.ADMIN in permissions
    }

    override fun createSearch() = SearchElement(
        mapOf(
            "username" to username
        )
    )
}
