24 lines
1005 B
Kotlin
24 lines
1005 B
Kotlin
package commands
|
|
|
|
import database.Repository
|
|
import models.HumanBeing
|
|
import network.Response
|
|
|
|
class AddIfMaxCommand(private val manager: Repository) : Command {
|
|
override val name = "add_if_max"
|
|
override val description = "добавить элемент, если он больше максимального"
|
|
override val type = CommandType.MODEL
|
|
override val args = listOf(CommandArgType.NONE)
|
|
|
|
override fun execute(args: List<String>, humanBeing: HumanBeing?): Response {
|
|
humanBeing ?: return Response(false, "[Ошибка] Объект HumanBeing не передан.")
|
|
val max = manager.getMax()
|
|
return if (max == null || humanBeing > max) {
|
|
manager.add(humanBeing)
|
|
Response(true, "Элемент добавлен (превышает максимум).")
|
|
} else {
|
|
Response(false, "Элемент не добавлен: не превышает текущий максимум (${max.name}).")
|
|
}
|
|
}
|
|
}
|