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



local orbit = asset.syncedResource({
  Name = "Comet C/2019 Y4 ATLAS",
  Type = "HttpSynchronization",
  Identifier = "horizons_c2019y4atlas",
  Version = 3
}) .. "c2019y4atlas.hrz"


local C2019Y4AtlasTrail = {
  Identifier = "C2019Y4AtlasTrail",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Renderable = {
    Type = "RenderableTrailTrajectory",
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = orbit
      -- Target: ATLAS (C/2019 Y4)
      -- Observer: SSB
      -- Start time: 1950-Jan-01 00:00:00.000 (first data point)
      -- End time: 2099-Dec-31 23:59:59.9985 (last data point)
      -- Step size: 90 000 steps
    },
    Color = { 0.533333, 0.850980, 0.996078 },
    EnableFade = false,
    StartTime = "1950 JAN 1 0:00:00",
    EndTime = "2100 JAN 1 00:00:00",
    SampleInterval = 52595, -- About 14h 36m 35.5200s in seconds
    TimeStampSubsampleFactor = 1
  },
  GUI = {
    Name = "C2019 Y4 Atlas Trail",
    Path = "/Solar System/Comets"
  }
}

local C2019Y4AtlasPosition = {
  Identifier = "C2019Y4AtlasPosition",
  Parent = sunTransforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "HorizonsTranslation",
      HorizonsTextFile = orbit
    }
  },
  GUI = {
    Name = "C/2019 Y4 Atlas",
    Path = "/Solar System/Comets",
    Description = "This is the position for C/2019 Y4 Atlas"
  }
}


asset.onInitialize(function()
  openspace.addSceneGraphNode(C2019Y4AtlasPosition)
  openspace.addSceneGraphNode(C2019Y4AtlasTrail)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(C2019Y4AtlasTrail)
  openspace.removeSceneGraphNode(C2019Y4AtlasPosition)
end)

asset.export(C2019Y4AtlasPosition)
asset.export(C2019Y4AtlasTrail)



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