package lila
package setup

import user.User
import ornicar.scalalib.Random

import org.joda.time.DateTime
import com.novus.salat.annotations.Key

case class UserConfig(
    id: String,
    ai: AiConfig,
    friend: FriendConfig,
    hook: HookConfig) {

  def withAi(c: AiConfig) = copy(ai = c)

  def withFriend(c: FriendConfig) = copy(friend = c)

  def withHook(c: HookConfig) = copy(hook = c)

  def encode = RawUserConfig(
    id = id,
    ai = ai.encode,
    friend = friend.encode,
    hook = hook.encode,
    date = DateTime.now)
}

object UserConfig {

  def default(id: String): UserConfig = UserConfig(
    id = id,
    ai = AiConfig.default,
    friend = FriendConfig.default,
    hook = HookConfig.default)
}

case class RawUserConfig(
    @Key("_id") id: String,
    ai: RawAiConfig,
    friend: RawFriendConfig,
    hook: RawHookConfig,
    date: DateTime) {

  def decode: Option[UserConfig] = for {
    trueAi ← ai.decode
    trueFriend ← friend.decode
    trueHook ← hook.decode
  } yield UserConfig(
    id = id,
    ai = trueAi,
    friend = trueFriend,
    hook = trueHook)
}

package lila
package setup

import user.User
import ornicar.scalalib.Random

import com.novus.salat.annotations.Key

case class UserConfig(
    id: String,
    ai: AiConfig,
    friend: FriendConfig,
    hook: HookConfig) {

  def withAi(c: AiConfig) = copy(ai = c)

  def withFriend(c: FriendConfig) = copy(friend = c)

  def withHook(c: HookConfig) = copy(hook = c)

  def encode = RawUserConfig(
    id = id,
    ai = ai.encode,
    friend = friend.encode,
    hook = hook.encode)
}

object UserConfig {

  def default(id: String): UserConfig = UserConfig(
    id = id,
    ai = AiConfig.default,
    friend = FriendConfig.default,
    hook = HookConfig.default)
}

case class RawUserConfig(
    @Key("_id") id: String,
    ai: RawAiConfig,
    friend: RawFriendConfig,
    hook: RawHookConfig) {

  def decode: Option[UserConfig] = for {
    trueAi ← ai.decode
    trueFriend ← friend.decode
    trueHook ← hook.decode
  } yield UserConfig(
    id = id,
    ai = trueAi,
    friend = trueFriend,
    hook = trueHook)
}

--- 
+++ 
@@ -4,6 +4,7 @@
 import user.User
 import ornicar.scalalib.Random
 
+import org.joda.time.DateTime
 import com.novus.salat.annotations.Key
 
 case class UserConfig(
@@ -22,7 +23,8 @@
     id = id,
     ai = ai.encode,
     friend = friend.encode,
-    hook = hook.encode)
+    hook = hook.encode,
+    date = DateTime.now)
 }
 
 object UserConfig {
@@ -38,7 +40,8 @@
     @Key("_id") id: String,
     ai: RawAiConfig,
     friend: RawFriendConfig,
-    hook: RawHookConfig) {
+    hook: RawHookConfig,
+    date: DateTime) {
 
   def decode: Option[UserConfig] = for {
     trueAi ← ai.decode
Add date field to user config mongodb object, to enable ttl
