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

local EarthBarycenter = {
  Identifier = "EarthBarycenter",
  Parent = transforms.SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "EARTH BARYCENTER",
      Observer = "SSB"
    }
  },
  GUI = {
    Name = "Earth Barycenter",
    Path = "/Solar System/Planets/Earth",
    Hidden = true
  }
}

local EarthCenter = {
  Identifier = "EarthCenter",
  Parent = EarthBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "EARTH",
      Observer = "EARTH BARYCENTER"
    }
  },
  GUI = {
    Name = "Earth Center",
    Path = "/Solar System/Planets/Earth",
    Hidden = true
  }
}

local EarthInertial = {
  -- The default reference frame for Earth-orbiting satellites
  Identifier = "EarthInertial",
  Parent = EarthCenter.Identifier,
  Transform = {
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "J2000",
      DestinationFrame = "GALACTIC",
    }
  },
  GUI = {
    Name = "Earth Inertial",
    Path = "/Solar System/Planets/Earth",
    Hidden = true
  }
}

local EarthIAU = {
  Identifier = "EarthIAU",
  Parent = EarthCenter.Identifier,
  Transform = {
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_EARTH",
      DestinationFrame = "GALACTIC",
    }
  },
  GUI = {
    Name = "Earth IAU",
    Path = "/Solar System/Planets/Earth",
    Hidden = true
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(EarthBarycenter)
  openspace.addSceneGraphNode(EarthCenter)
  openspace.addSceneGraphNode(EarthInertial)
  openspace.addSceneGraphNode(EarthIAU)
end)

asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(EarthIAU)
  openspace.removeSceneGraphNode(EarthInertial)
  openspace.removeSceneGraphNode(EarthCenter)
  openspace.removeSceneGraphNode(EarthBarycenter)
end)

asset.export(EarthBarycenter)
asset.export(EarthCenter)
asset.export(EarthInertial)
asset.export(EarthIAU)

asset.meta = {
  Name = "Earth Transforms",
  Version = "1.1",
  Description = [[Earth transforms: Earth Barycenter, Earth Center, Earth Inertial, Earth
    IAU. A scene graph node is created for each transform]],
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
