package wow.doge.mygame

import org.scalatest.funsuite.AnyFunSuite
import monix.bio.Task
import scala.concurrent.duration._
import monix.execution.Scheduler.Implicits.global
import wow.doge.mygame.subsystems.scriptsystem.ScriptCompiler
import io.odin.consoleLogger
import wow.doge.mygame.implicits._

class MonixScriptCompilerTest extends AnyFunSuite {

  test("some-test") {
    ScriptCompiler(consoleLogger[Task]())
      .use(scriptCompiler =>
        for {
          // _ <-
          //   scriptCompiler.source
          //     .doOnNextF(el => Task(println(s"Got $el")))
          //     .completedL
          //     .toIO
          //     .hideErrors
          //     .startAndForget
          response <- scriptCompiler.request(
            ScriptCompiler.Get(
              os.pwd / "assets" / "scripts" / "scala" / "hello2.sc",
              _,
              false
            )
          )(20.seconds)
          _ <- Task(pprint.log(response.toString))
          // _ <- Task.sleep(4.seconds)
          //   _ <- scriptCompiler.tell(
          //     ScriptCompiler.CompileAny(
          //       os.pwd / "assets" / "scripts" / "scala" / "hello2.sc"
          //     )
          //   )
          // _ <- Task.sleep(4.seconds)
          // _ <- Task.sleep(8.seconds)
        } yield ()
      )
      .runSyncUnsafe(20.seconds)
  }
}
