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

local trajectory = asset.syncedResource({
  Name = "C-2019 Q4 Borisov Trajectory",
  Type = "HttpSynchronization",
  Identifier = "borisov_horizons",
  Version = 2
})

local C2019Q4BorisovTrail = {
  Identifier = "C2019Q4BorisovTrail",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailTrajectory",
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = trajectory .. "horizons_c2019q4borisov.hrz"
      -- Target: Borisov (C/2019 Q4)
      -- Observer: SSB
      -- Start time: 2015-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 = "2015 JAN 01 00:00:00",
    EndTime = "2050 JAN 01 00:00:00",
    SampleInterval = 60*60*24 -- = 86 400 seconds in 1 day
  },
  GUI = {
    Name = "C/2019 Q4 Borisov Trail",
    Path = "/Solar System/Interstellar",
    Description = [[Trail of C-2019 Q4 Borisov from 2015 JAN 01 00:00:00
    to 2050 JAN 01 00:00:00. Data from JPL Horizons]]
  }
}

local C2019Q4BorisovPosition = {
  Identifier = "C2019Q4BorisovPosition",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = trajectory .. "horizons_c2019q4borisov.hrz"
    }
  },
  GUI = {
    Name = "C/2019 Q4 Borisov",
    Path = "/Solar System/Interstellar",
    Description = [[Position of C-2019 Q4 Borisov from 2015 JAN 01 00:00:00
    to 2050 JAN 01 00:00:00. Data from JPL Horizons]]
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(C2019Q4BorisovPosition)
  openspace.addSceneGraphNode(C2019Q4BorisovTrail)
end)
    
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(C2019Q4BorisovTrail)
  openspace.removeSceneGraphNode(C2019Q4BorisovPosition)
end)
    
asset.export(C2019Q4BorisovPosition)
asset.export(C2019Q4BorisovTrail)



asset.meta = {
  Name = "C/2019 Q4 Borisov",
  Version = "1.2",
  Description = [[This asset contains the trail and position of C-2019 Q4 Borisov from
    2015 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 = [[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]]
}
