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

local trajectory = asset.syncedResource({
  Name = "'Oumuamua Trajectory",
  Type = "HttpSynchronization",
  Identifier = "oumuamua_horizons",
  Version = 2
})

local OumuamuaTrail = {
  Identifier = "OumuamuaTrail",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailTrajectory",
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = trajectory .. "horizons_oumuamua.hrz"
      -- Target: 1I/'Oumuamua (A/2017 U1)
      -- Observer: SSB
      -- Start time: 2014-Jan-01 00:00:00 (first data point)
      -- End time: 2050-Jan-01 00:00:00 (last data point)
      -- Step size: 1 day
    },
    Color = { 0.9, 0.9, 0.0 },
    StartTime = "2014 JAN 01 00:00:00",
    EndTime = "2050 JAN 01 00:00:00",
    SampleInterval = 86400,
    TimeStampSubsampleFactor = 1
  },
  GUI = {
    Name = "'Oumuamua Trail",
    Path = "/Solar System/Interstellar",
    Description = [[Trail of 'Oumuamua from 2014 JAN 01 00:00:00 to 2050 JAN 01 00:00:00.
      Data from JPL Horizons]],
  }
}

local OumuamuaPosition = {
  Identifier = "OumuamuaPosition",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = trajectory .. "horizons_oumuamua.hrz"
    },
  },
  GUI = {
    Name = "'Oumuamua",
    Path = "/Solar System/Interstellar",
    Description = [[Position of 'Oumuamua from 2014 JAN 01 00:00:00 to 2050 JAN 01
      00:00:00. Data from JPL Horizons]],
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(OumuamuaPosition)
  openspace.addSceneGraphNode(OumuamuaTrail)
end)
    
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(OumuamuaTrail)
  openspace.removeSceneGraphNode(OumuamuaPosition)
end)
    
asset.export(OumuamuaPosition)
asset.export(OumuamuaTrail)



asset.meta = {
  Name = "'Oumuamua",
  Version = "1.2",
  Description = [[This asset contains the trail and position of 'Oumuamua from 2014
    JAN 01 00:00:00 to 2050 JAN 01 00:00:00. Data from JPL Horizons]],
  Author = "OpenSpace Team",
  URL = "https://ssd.jpl.nasa.gov/horizons.cgi",
  License = "NASA"
}
