import Foundation
class DiHabit: DiSkillV2 {
private var habitsPositive = UniqueItemSizeLimitedPriorityQueue<String>()
private var habitP = AXCmdBreaker("i should")
private var temp = ""
private var habitsNegative = UniqueItemSizeLimitedPriorityQueue<String>()
private var habitN = AXCmdBreaker("i must not")
private var dailies = UniqueItemSizeLimitedPriorityQueue<String>()
private var dailyCmdBreaker = AXCmdBreaker("i out to")
private var weekends = UniqueItemSizeLimitedPriorityQueue<String>()
private var weekendCmdBreaker = AXCmdBreaker("i have to")
private var expirations = UniqueItemSizeLimitedPriorityQueue<String>()
private var expirationsCmdBreaker = AXCmdBreaker("i got to")
private var todo = TODOListManager(5)
private var toDoCmdBreaker = AXCmdBreaker("i need to")
private var clearCmdBreaker = AXCmdBreaker("clear")
private var getterCmdBreaker = AXCmdBreaker("random")
private var strOrDefault = AXStrOrDefault()
private var gamification = AXGamification()
private var punishments = AXGamification()
override init() {
habitsPositive.setLimit(15)
habitsNegative.setLimit(5)
dailies.setLimit(3)
weekends.setLimit(3)
expirations.setLimit(3)
}
func getGamification() -> AXGamification {
return gamification
}
func getPunishments() -> AXGamification {
return punishments
}
override func input(_ ear: String, _ skin: String, _ eye: String) {
if ear.isEmpty() { return }
if ear.contains("i") {
temp = habitP.extractCmdParam(ear)
if !temp.isEmpty() {
habitsPositive.add(temp)
temp = ""
setVerbatimAlg(4, "habit registered")
return
}
temp = habitN.extractCmdParam(ear)
if !temp.isEmpty() {
habitsNegative.add(temp)
temp = ""
setVerbatimAlg(4, "bad habit registered")
return
}
temp = dailyCmdBreaker.extractCmdParam(ear)
if !temp.isEmpty() {
dailies.add(temp)
temp = ""
setVerbatimAlg(4, "daily registered")
return
}
temp = weekendCmdBreaker.extractCmdParam(ear)
if !temp.isEmpty() {
weekends.add(temp)
temp = ""
setVerbatimAlg(4, "prep registered")
return
}
temp = expirationsCmdBreaker.extractCmdParam(ear)
if !temp.isEmpty() {
expirations.add(temp)
temp = ""
setVerbatimAlg(4, "expiration registered")
return
}
temp = toDoCmdBreaker.extractCmdParam(ear)
if !temp.isEmpty() {
todo.addTask(temp)
temp = ""
setVerbatimAlg(4, "task registered")
return
}
}
temp = getterCmdBreaker.extractCmdParam(ear)
if !temp.isEmpty() {
switch temp {
case "habit":
setVerbatimAlg(4, strOrDefault.getOrDefault(habitsPositive.getRNDElement(), "no habits registered"))
return
case "bad habit":
setVerbatimAlg(4, strOrDefault.getOrDefault(habitsNegative.getRNDElement(), "no bad habits registered"))
return
case "daily":
setVerbatimAlg(4, strOrDefault.getOrDefault(dailies.getRNDElement(), "no dailies registered"))
return
case "weekend", "prep":
setVerbatimAlg(4, strOrDefault.getOrDefault(weekends.getRNDElement(), "no preps registered"))
return
case "expirations", "expiration":
if expirations.getAsList().isEmpty {
setVerbatimAlg(4, "no expirations registered")
return
}
setVerbatimAlgFromList(4, expirations.getAsList())
return
case "task":
setVerbatimAlg(4, strOrDefault.getOrDefault(todo.getTask(), "no new tasks registered"))
return
case "to do":
setVerbatimAlg(4, strOrDefault.getOrDefault(todo.getOldTask(), "no tasks registered"))
return
default:
break
}
}
if ear.contains("completed") {
if !diSkillUtils.strContainsList(ear, habitsPositive.getAsList()).isEmpty {
gamification.increment()
setVerbatimAlg(4, "good boy")
return
}
if !diSkillUtils.strContainsList(ear, habitsNegative.getAsList()).isEmpty {
punishments.increment()
setVerbatimAlg(4, "bad boy")
return
}
if !diSkillUtils.strContainsList(ear, dailies.getAsList()).isEmpty {
gamification.increment()
setVerbatimAlg(4, "daily engaged")
return
}
if !diSkillUtils.strContainsList(ear, weekends.getAsList()).isEmpty {
setVerbatimAlg(4, "prep engaged")
return
}
}
switch ear {
case "clear habits":
habitsPositive.clear()
setVerbatimAlg(4, "habits cleared")
case "clear bad habits":
habitsNegative.clear()
setVerbatimAlg(4, "bad habits cleared")
case "clear dailies":
dailies.clear()
setVerbatimAlg(4, "dailies cleared")
case "clear preps", "clear weekends":
weekends.clear()
setVerbatimAlg(4, "preps cleared")
case "clear expirations":
expirations.clear()
setVerbatimAlg(4, "expirations cleared")
case "clear tasks", "clear task", "clear to do":
todo.clearAllTasks()
setVerbatimAlg(4, "tasks cleared")
case "clear all habits":
habitsPositive.clear()
habitsNegative.clear()
dailies.clear()
weekends.clear()
expirations.clear()
todo.clearAllTasks()
setVerbatimAlg(4, "all habits cleared")
default:
if ear.contains("clear") {
temp = clearCmdBreaker.extractCmdParam(ear)
if todo.containsTask(temp) {
todo.clearTask(temp)
setVerbatimAlg(4, temp + " task cleared")
temp = ""
}
}
}
}
}