local transforms = asset.require("scene/solarsystem/planets/earth/transforms")



local omm = asset.syncedResource({
  Name = "Satellite OMM Data (SNPP)",
  Type = "UrlSynchronization",
  Identifier = "satellite_omm_data_snpp",
  Url = "https://www.celestrak.com/NORAD/elements/gp.php?CATNR=37849&FORMAT=kvn",
  Filename = "SNPP.txt",
  Override = true
})


local SNPP = {
  Identifier = "SNPP",
  Parent = transforms.EarthInertial.Identifier,
  InteractionSphere = 30,
  Transform = {
    Translation = {
      Type = "GPTranslation",
      Observer = transforms.EarthInertial.Identifier,
      File = omm .. "SNPP.txt",
      Format = "OMM"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "GALACTIC",
      DestinationFrame = "J2000",
    }
  },
  Tag = { "earth_satellite", "SNPP" },
  GUI = {
    Name = "SNPP",
    Path = "/Solar System/Planets/Earth/Satellites/SNPP"
  }
}

local SNPPTrail = {
  Identifier = "SNPP_trail",
  Parent = transforms.EarthInertial.Identifier,
  Renderable = {
    Type = "RenderableTrailOrbit",
    Translation = {
      Type = "GPTranslation",
      Observer = transforms.EarthInertial.Identifier,
      File = omm .. "SNPP.txt",
      Format = "OMM",
      RenderBinMode = "PostDeferredTransparent"
    },
    Color = { 0.9, 0.6715, 0.0 },
    Fade = 1.5,
    Resolution = 320
  },
  Tag = { "earth_satellite", "SNPP" },
  GUI = {
    Name = "SNPP Trail",
    Path = "/Solar System/Planets/Earth/Satellites/SNPP"
  }
}

local SNPPLabel = {
  Identifier = "SNPPLabel",
  Parent = SNPP.Identifier,
  Renderable = {
    Enabled = false,
    Type = "RenderableLabel",
    Text = "SNPP",
    FontSize = 70.0,
    Size = 4.0,
    MinMaxSize = { 1, 100 },
    OrientationOption = "Camera View Direction",
    BlendMode = "Additive",
    EnableFading = true,
    FadeUnit = "au",
    FadeDistances = { 1.5, 15.0 },
    FadeWidths = { 1.0, 25.0 }
  },
  Tag = { "solarsystem_labels" },
  GUI = {
    Name = "SNPP Label",
    Path = "/Solar System/Planets/Earth"
  }
}


asset.onInitialize(function()
  local s = openspace.space.readKeplerFile(omm .. "SNPP.txt", "OMM")
  SNPPTrail.Renderable.Period = s[1].Period / (60 * 60 * 24)

  openspace.addSceneGraphNode(SNPP)
  openspace.addSceneGraphNode(SNPPTrail)
  openspace.addSceneGraphNode(SNPPLabel)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(SNPPLabel)
  openspace.removeSceneGraphNode(SNPPTrail)
  openspace.removeSceneGraphNode(SNPP)
end)

asset.export(SNPP)
asset.export(SNPPTrail)
asset.export(SNPPLabel)



asset.meta = {
  Name = "SNPP",
  Version = "1.0",
  Description = [[Trail for SNPP. trail from Celestrak. Can be used in conjunction with
    VIIRS SNPP (Temporal) layer for Earth]],
  Author = "OpenSpace Team",
  URL = "https://celestrak.com/",
  License = "NASA"
}
