local sunTransforms = asset.require("scene/solarsystem/sun/transforms")
local marsTransforms = asset.require("scene/solarsystem/planets/mars/transforms")
local spice = asset.require("./spice")



local StartTime = "2020 JUL 17 13:56:42"
local ApproachMars = "2021 FEB 11 20:32:16"
local EndTime = "2021 FEB 18 20:32:16"

local PerseveranceTrailSun = {
  Identifier = "PerseveranceTrailSun",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailTrajectory",
    Translation = {
      Type = "SpiceTranslation",
      Target = spice.ID,
      Observer = "SSB"
    },
    Color = { 0.2, 0.7, 0.1 },
    StartTime = StartTime,
    EndTime = EndTime,
    SampleInterval = 100,
    Enabled = false
  },
  GUI = {
    Name = "Perseverance Trail (Sun)",
    Path = "/Solar System/Missions/Perseverance"
  }
}

local PerseveranceTrailMars = {
  Identifier = "PerseveranceTrailMars",
  Parent = marsTransforms.MarsBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailTrajectory",
    Translation = {
      Type = "SpiceTranslation",
      Target = spice.ID,
      Observer = "MARS BARYCENTER"
    },
    Color = { 0.7, 0.9, 0.6 },
    StartTime = ApproachMars,
    EndTime = "2021 FEB 18 20:43:48",
    SampleInterval = 100,
    Enabled = false
  },
  GUI = {
    Name = "Perseverance Trail (Mars)",
    Path = "/Solar System/Missions/Perseverance"
  }
}


asset.onInitialize(function()
  openspace.spice.loadKernel(spice.Kernels)

  openspace.addSceneGraphNode(PerseveranceTrailSun)
  openspace.addSceneGraphNode(PerseveranceTrailMars)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(PerseveranceTrailMars)
  openspace.removeSceneGraphNode(PerseveranceTrailSun)

  openspace.spice.unloadKernel(spice.Kernels)
end)

asset.export(PerseveranceTrailSun)
asset.export(PerseveranceTrailMars)
