asset.require("spice/base")



-- Barycenter of the solar system, expressed in the Galactic frame
local SolarSystemBarycenter = {
  Identifier = "SolarSystemBarycenter",
  -- No parent; this node is attached to the scene graph root
  TimeFrame = { -- Using Spice kernels for 1850-2150
    Type = "TimeFrameInterval",
    Start = "1550-JAN-01",
    End = "2650-JAN-22"
  },
  GUI = {
    Name = "Solar System Barycenter",
    Path = "/Solar System",
    Description = "Barycenter of the solar system, expressed in the Galactic frame",
    Hidden = true
  }
}

local SunCenter = {
  Identifier = "SunCenter",
  Parent = SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "SUN",
      Observer = "SSB"
    }
  },
  GUI = {
    Name = "SUN Center",
    Path = "/Solar System/Sun",
    Description = "Spice frame for the Sun",
    Hidden = true
  }
}

-- Spice frame for the Sun
local SunIAU = {
  Identifier = "SunIAU",
  Parent = SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "SUN",
      Observer = "SSB"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "IAU_SUN",
      DestinationFrame = "GALACTIC"
    }
  },
  GUI = {
    Name = "SUN IAU",
    Path = "/Solar System/Sun",
    Description = "Spice frame for the Sun",
    Hidden = true
  }
}

local SunECLIPJ2000 = {
  Identifier = "SunECLIPJ2000",
  Parent = SolarSystemBarycenter.Identifier,
  Transform = {
    Translation = {
      Type = "SpiceTranslation",
      Target = "SUN",
      Observer = "SSB"
    },
    Rotation = {
      Type = "SpiceRotation",
      SourceFrame = "ECLIPJ2000",
      DestinationFrame = "GALACTIC"
    }
  },
  GUI = {
    Name = "SUN J2000",
    Path = "/Solar System/Sun",
    Description = "Spice rotation for Mean ecliptic and equinox of J2000",
    Hidden = true
  }
}

asset.onInitialize(function()
  openspace.addSceneGraphNode(SolarSystemBarycenter)
  openspace.addSceneGraphNode(SunCenter)
  openspace.addSceneGraphNode(SunIAU)
  openspace.addSceneGraphNode(SunECLIPJ2000)
end)
    
asset.onDeinitialize(function()
  openspace.removeSceneGraphNode(SunECLIPJ2000)
  openspace.removeSceneGraphNode(SunIAU)
  openspace.removeSceneGraphNode(SunCenter)
  openspace.removeSceneGraphNode(SolarSystemBarycenter)
end)
    
asset.export(SolarSystemBarycenter)
asset.export(SunCenter)
asset.export(SunIAU)
asset.export(SunECLIPJ2000)



asset.meta = {
  Name = "Sun Transforms",
  Version = "1.1",
  Description = "Sun transforms: Solar System Barycenter, SUN IAU and SUN J2000",
  Author = "OpenSpace Team",
  URL = "http://openspaceproject.com",
  License = "MIT license"
}
