local api = require("simctl.api")
local aw = require("simctl.lib.async")

aw.async(function()
  vim.print("Test: Boot device")
  aw.await(function(cb)
    api.boot({}, cb)
  end)
  vim.print("Should have booted device")

  vim.print("Test: Launch app from device picker")
  aw.await(function(cb)
    api.launch({}, cb)
  end)
  vim.print("Should have launched app")

  vim.print("Test: Launch app on booted device")
  aw.await(function(cb)
    api.launch({ deviceId = "booted" }, cb)
  end)
  vim.print("Should have launched app")

  vim.print("Test: Launch News on booted device")
  aw.await(function(cb)
    api.launch({ deviceId = "booted", appId = "com.apple.news" }, cb)
  end)
  vim.print("Should have launched News")

  vim.print("Test: Terminate News on booted device")
  aw.await(function(cb)
    api.terminate({ deviceId = "booted", appId = "com.apple.news" }, cb)
  end)
  vim.print("Should have launched News")

  vim.print("Test: Open url on device from device picker")
  aw.await(function(cb)
    api.openurl({ url = "https://xkcd.com" }, cb)
  end)
  vim.print("Should have opened https://xkcd.com")

  vim.print("Test: Open url on booted device")
  aw.await(function(cb)
    api.openurl({ deviceId = "booted", url = "https://github.com" }, cb)
  end)
  vim.print("Should have opened https://github.com")

  vim.print("Test: Set status bar time")
  aw.await(function(cb)
    api.statusbar({ time = "09:41" }, cb)
  end)
  vim.print("Should have set the status bar time to 09:41")

  vim.print("Test: Set content size to huge")
  aw.await(function(cb)
    api.ui.setContentSize({ size = api.ui.ContentSize.ACCESSIBILITY_EXTRA_EXTRA_LARGE }, cb)
  end)
  vim.print("Should have opened https://xkcd.com")

  vim.print("Test: Shut down device")
  aw.await(function(cb)
    api.shutdown({}, cb)
  end)
  vim.print("Should have shut down device")

  vim.print("Test: Erase (pick same device that content size was set on)")
  aw.await(function(cb)
    api.erase({}, cb)
  end)

  vim.print("Test: Boot same device")
  aw.await(function(cb)
    api.boot({}, cb)
  end)
  vim.print("Should have booted device with standard settings")
end)
