local globeIdentifier = asset.require("../../earth").Earth.Identifier


local Name = "Polar Orbiting: NOAA-17 and NOAA-18"
local Identifier = "noaa-sos-atmosphere-sunsync_sat"
local Description = [[Satellites allow scientists to observe the Earth from above the 
atmosphere. The National Oceanic and Atmospheric Administration, NOAA, has several 
different types of satellites, including geostationary and polar orbiting satellites. 
These datasets show the path of Polar-orbiting Operational Environmental Satellites, or 
POES for short. NOAA has two POES in operation currently, a morning and afternoon 
satellite. The morning satellite crosses the equator on the sun-light side of the Earth 
in the morning, and the afternoon satellite crosses in the afternoon. Both satellites 
orbit the Earth 14.1 times per day]]
local URL = "https://sos.noaa.gov/catalog/datasets/polar-orbiting-noaa-17-and-noaa-18/"


local syncedDirectory = asset.syncedResource({
  Name = Name,
  Type = "HttpSynchronization",
  Identifier = Identifier,
  Version = 1
})

local imagesDestination = syncedDirectory .. "images"

local layer = {
  Identifier = Identifier,
  Name = Name,
  Enabled = asset.enabled,
  Type = "TemporalTileLayer",
  Mode = "Folder",
  Folder = {
    Folder = imagesDestination,
    -- See https://en.cppreference.com/w/cpp/io/manip/get_time for an explanation of the
    -- time formatting string
    Format = "sunsync_%Y%j%H%M.jpg"
  },
  Description = Description
}

asset.onInitialize(function()
  if not openspace.directoryExists(imagesDestination) then
    openspace.printInfo("Extracting " .. Name)
    openspace.unzipFile(syncedDirectory .. "2048.zip", imagesDestination, true)
  end

  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.onDeinitialize(function()
  openspace.globebrowsing.deleteLayer(globeIdentifier, "ColorLayers", layer)
end)

asset.export(layer)


asset.meta = {
  Name = Name,
  Version = "1.0",
  Description = Description .. "Data provided by the National Oceanic and Atmospheric Administration",
  Author = "National Oceanic and Atmospheric Administration",
  URL = URL,
  License = "https://sos.noaa.gov/copyright/"
}
