package wow.doge.mygame.game.entities

import akka.actor.typed.ActorRef
import akka.actor.typed.LogOptions
import akka.actor.typed.scaladsl.Behaviors
import com.typesafe.scalalogging.Logger
import org.slf4j.event.Level
import wow.doge.mygame.subsystems.events.PlayerCameraEvent
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
import wow.doge.mygame.subsystems.movement.ImMovementActor

object PlayerMovementEventListener {
  import PlayerMovementEvent._
  def apply(movementActor: ActorRef[ImMovementActor.Command]) =
    Behaviors.logMessages(
      LogOptions()
        .withLevel(Level.TRACE)
        .withLogger(
          Logger[PlayerMovementEventListener.type].underlying
        ),
      Behaviors.setup[PlayerMovementEvent](ctx =>
        Behaviors.receiveMessage {
          case PlayerMovedLeft(pressed) =>
            movementActor ! ImMovementActor.MoveLeft(pressed)
            Behaviors.same
          case PlayerMovedRight(pressed) =>
            movementActor ! ImMovementActor.MoveRight(pressed)
            Behaviors.same
          case PlayerMovedForward(pressed) =>
            movementActor ! ImMovementActor.MoveUp(pressed)
            Behaviors.same
          case PlayerMovedBackward(pressed) =>
            movementActor ! ImMovementActor.MoveDown(pressed)
            Behaviors.same
          case PlayerJumped =>
            movementActor ! ImMovementActor.Jump
            Behaviors.same
          // case PlayerTurnedRight =>
          //   movementActor ! ImMovementActor.RotateRight
          //   Behaviors.same
          // case PlayerTurnedLeft =>
          //   movementActor ! ImMovementActor.RotateLeft
          //   Behaviors.same
        }
      )
    )
}

//not used
object PlayerCameraEventListener {
  import PlayerCameraEvent._
  def apply(playerCameraActor: ActorRef[PlayerCameraActor.Command]) =
    Behaviors.logMessages(
      LogOptions()
        .withLevel(Level.TRACE)
        .withLogger(
          Logger[PlayerCameraEventListener.type].underlying
        ),
      Behaviors.setup[PlayerCameraEvent](ctx =>
        Behaviors.receiveMessagePartial {
          case CameraMovedUp =>
            playerCameraActor ! PlayerCameraActor.RotateUp
            Behaviors.same
          case CameraMovedDown =>
            playerCameraActor ! PlayerCameraActor.RotateDown
            Behaviors.same
          case CameraLeft =>
            playerCameraActor ! PlayerCameraActor.RotateLeft
            Behaviors.same
          case CameraRight =>
            playerCameraActor ! PlayerCameraActor.RotateRight
            Behaviors.same
        }
      )
    )
}
