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


local Name = "Typhoon Haiyan - Oct - Nov 2013"
local Identifier = "noaa-sos-atmosphere-typhoon_haiyan"
local Description = [[Typhoon Haiyan, also known in the Phillippines as Typhoon Yolanda, 
may be the strongest recorded tropical cyclone to make landfall with sustained speeds up 
to 195 mph. If confirmed, it would beat the previous record holder, Hurricane Camille 
(1969). This dataset is taken from the Real-Time Linear IR satellite dataset from October 
30th to November 12th, 2013]]
local URL = "https://sos.noaa.gov/catalog/datasets/typhoon-haiyan-oct-nov-2013/"


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 = "linear_rgb_cyl_%Y%m%d_%H%M.jpg"
  },
  Description = Description
}

local track = {
  Identifier = Identifier .. "-track",
  Name = Name .. " (Track)",
  Enabled = asset.enabled,
  FilePath = syncedDirectory .. "track.png",
  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)
  openspace.globebrowsing.addLayer(globeIdentifier, "ColorLayers", track)
end)

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

asset.export(layer)
asset.export(track)


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/"
}
