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



local sync = asset.syncedResource({
  Name = "Swift Tuttle Orbit",
  Type = "HttpSynchronization",
  Identifier = "swift_tuttle_horizons",
  Version = 3
})


local SwiftTuttleTrail = {
  Identifier = "SwiftTuttleTrail",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailOrbit",
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = sync .. "horizons_swifttuttle.hrz"
      -- Target: 109P/Swift-Tuttle (1995 epoch)
      -- Observer: SSB
      -- Start time: 1879-Jun-27 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 },
    Period = 48577.2124, -- Orbit time 133 years
    Resolution = 48577 -- Step size: 1 day
  },
  GUI = {
    Name = "Swift Tuttle Trail",
    Path = "/Solar System/SSSB"
  }
}

local SwiftTuttlePosition = {
  Identifier = "SwiftTuttlePosition",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = sync .. "horizons_swifttuttle.hrz"
    }
  },
  GUI = {
    Name = "Swift Tuttle Position",
    Path = "/Solar System/SSSB"
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(SwiftTuttlePosition)
  openspace.addSceneGraphNode(SwiftTuttleTrail)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(SwiftTuttleTrail)
  openspace.removeSceneGraphNode(SwiftTuttlePosition)
end)

asset.export(SwiftTuttlePosition)
asset.export(SwiftTuttleTrail)



asset.meta = {
  Name = "Swift Tuttle",
  Version = "1.2",
  Description = [[Position and Trail of Swift Tuttle from 1879 JUN 27 to 2050 JAN 01. 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]]
}
