package wow.doge.mygame.executors

import com.typesafe.scalalogging.Logger
import monix.execution.Scheduler
import monix.execution.UncaughtExceptionReporter

final case class Schedulers(
    blockingIO: Schedulers.IoScheduler,
    async: Schedulers.AsyncScheduler,
    fx: Schedulers.FxScheduler
)

object Schedulers {
  val reporter = UncaughtExceptionReporter { ex =>
    val logger = Logger[Schedulers]
    logger.error("Uncaught exception", ex)
  }

  val default = Schedulers(
    IoScheduler(
      Scheduler
        .io()
        .withUncaughtExceptionReporter(Schedulers.reporter)
    ),
    AsyncScheduler(
      Scheduler.global
        .withUncaughtExceptionReporter(Schedulers.reporter)
    ),
    FxScheduler(
      JFXExecutionContexts.fxScheduler
        .withUncaughtExceptionReporter(Schedulers.reporter)
    )
  )

  case class AsyncScheduler(value: Scheduler)
  case class IoScheduler(value: Scheduler)
  case class FxScheduler(value: Scheduler)

}
