local sunTransforms = asset.require("scene/solarsystem/sun/transforms")

local orbit = asset.syncedResource({
  Name = "Tesla Roadster Orbit",
  Type = "HttpSynchronization",
  Identifier = "tesla_horizons",
  Version = 2
})

local TeslaRoadsterTrail = {
  Identifier = "TeslaRoadsterTrail",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailOrbit",
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = orbit .. "horizons_tesla.hrz"
      -- Target: SpaceX Roadster (spacecraft) (-143205)
      -- Observer: SSB
      -- Start time: 2018-Feb-07 03:00:00 (first data point)
      -- End time: 2089-Dec-31 03:00:00 (last data point)
      -- Step size: 1 day
    },
    Color = { 0.9, 0.9, 0.0 },
    Period = 557, -- Orbit time 557 days
    Resolution = 557 -- Step size 1 day
  },
  GUI = {
    Name = "Tesla Roadster Trail",
    Path = "/Solar System/SSSB"
  }
}

local TeslaPosition = {
  Identifier = "TeslaPosition",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = orbit .. "horizons_tesla.hrz"
    }
  },
  GUI = {
    Name = "Tesla Roadster",
    Path = "/Solar System/SSSB",
    Description = [[Position and Trail of Tesla Roadster from 2018 FEB 7 03:00:00
      to 2089 DEC 31 03:00:00. Data from JPL Horizons]]
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(TeslaPosition)
  openspace.addSceneGraphNode(TeslaRoadsterTrail)
end)
    
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(TeslaRoadsterTrail)
  openspace.removeSceneGraphNode(TeslaPosition)
end)
    
asset.export(TeslaPosition)
asset.export(TeslaRoadsterTrail)



asset.meta = {
  Name = "Tesla Roadster",
  Version = "1.2",
  Description = [[Position and Trail of Tesla Roadster from 2018 FEB 7 03:00:00 to
    2089 DEC 31 03:00:00. Data from JPL Horizons]],
  Author = "OpenSpace Team",
  URL = "https://ssd.jpl.nasa.gov/horizons.cgi",
  License = [[JPL-authored documents are sponsored by NASA under Contract NAS7-030010. All
    documents available from this server may be protected under the U.S. and Foreign
    Copyright Laws]]
}
