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

local horizons = asset.syncedResource({
  Name = "5 Astraea Trajectory",
  Type = "HttpSynchronization",
  Identifier = "astraea_horizons",
  Version = 1
})

local AstraeaTrail = {
  Identifier = "AstraeaTrail",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailOrbit",
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = horizons .. "horizons_astraea.hrz"
      -- Target: 5 Astraea (A845 XA)
      -- Observer: SSB
      -- Start time: 2014-Jan-01 00:00 (first data point)
      -- End time: 2050-Jan-01 00:00 (last data point)
      -- Step size: 1 day
    },
    Color = { 0.9, 0.9, 0.0 },
    Period = 1507, -- Orbit time 1507 days
    Resolution = 1507 -- Step size of 1 day
  },
  GUI = {
    Name = "5 Astraea Trail",
    Path = "/Solar System/Interstellar"
  }
}

local AstraeaPosition = {
  Identifier = "AstraeaPosition",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = horizons .. "horizons_astraea.hrz"
    }
  },
  GUI = {
    Name = "5 Astraea",
    Path = "/Solar System/Interstellar"
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(AstraeaPosition)
  openspace.addSceneGraphNode(AstraeaTrail)
end)
    
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(AstraeaTrail)
  openspace.removeSceneGraphNode(AstraeaPosition)
end)
    
asset.export(AstraeaPosition)
asset.export(AstraeaTrail)



asset.meta = {
  Name = "5 Astraea",
  Version = "1.2",
  Description = [[This asset contains the trail and position of 5 Astraea from
    2014 JAN 01 00:00:00 to 2050 JAN 01 00:00:00. Data from JPL Horizons]],
  Author = "Zach Shaffer",
  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]]
}
