#lang racket/base

(module+ test
  (require rackunit)
  ;; Tests to be run with raco test
  )

(module+ main
  (require
    "src/webcontainer/webcontainer.rkt"
    "src/webcontainer/website.rkt"
    "src/pages/sitemap.rkt"
    "src/pages/home.rkt"
    "src/pages/other-generators.rkt"
    "src/pages/arnytron.rkt"
    "src/pages/floraverse.rkt"
    "src/pages/yggdrasil.rkt"
    "src/pages/flag.rkt"
    "src/pages/road-map.rkt"
    "src/pages/island.rkt"
    "src/pages/notepad.rkt"
    "configuration.rkt")
  ; Website
  (define *website*
    (website
      "" weblet pages:home
      ("AboutMe" weblet pages:about-me)
      ("AboutFeuforeve" weblet pages:about-feuforeve)
      ("Fonts" weblet pages:fonts)
      ("Gatel" weblet pages:gatel)
      ; ToyCatCreator used to be hosted here before moving on its own page
      ("ToyCatCreator" redirection "http://beleth.pink")
      ; Symlinks to the character generator
      ("generator-v1" symlink "/Floraverse/CharacterGenerator")
      ("generator-v2" symlink "/Floraverse/CharacterGenerator")
      ("generator" symlink "/Floraverse/CharacterGenerator")
      ("generator2" symlink "/Floraverse/CharacterGenerator")
      ("FloraCharacterGenerator" symlink "/Floraverse/CharacterGenerator")
      ; Floraverse section
      ("Floraverse" weblet pages:floraverse
        ("CharacterGenerator" weblet pages:floraverse-character-generator
          ("Tweet" weblet pages:floraverse-character-generator-tweet))
        ("AboutCharacterGenerator" weblet pages:floraverse-character-generator-about)
        ("Calendar" weblet pages:floraverse-calendar)
        ("Calendar/{month}/{day}" matching-weblet pages:floraverse-calendar)
        )
      ; Yggdrasil generator
      ("Yggdrasil" weblet pages:yggdrasil
        ("About" weblet pages:yggdrasil-about)
        ("Raw" weblet pages:yggdrasil-raw-image)
        )
      ; Flag generator
      ("FlagGenerator" weblet pages:flag
        ("About" weblet pages:flag-about)
        ("RawFlag" weblet pages:flag-raw)
        )
      ; Road Map
      ("RoadMap" weblet pages:road-map
        ("Raw" weblet pages:road-map-raw-image)
        )
      ; Daily Island
      ("DailyIsland" weblet pages:daily-island
        ("Archives" weblet pages:daily-island-archives)
        ("About" weblet pages:daily-island-about)
        )
      ; Other generators
      ("Generators" weblet pages:other-generators
        ("ColorScheme" weblet pages:color-scheme-generator)
        ("PictogrammicAdventurer" weblet pages:pictogrammic-adventurer)
        ("Phonagen" weblet pages:phonagen)
        ("GenerCommunes" weblet pages:gener-communes)
        ("Pizzeria" weblet pages:pizzeria)
        )
      ; ArnYtron3000
      ("ArnYtron3000" weblet pages:arnytron
        ("brut" weblet pages:arnytron-raw)
        ("json" weblet pages:arnytron-json)
        ("About" weblet pages:arnytron-about)
        ("vraie" weblet pages:arnytron-real)
        ("vraie/{date}" matching-weblet pages:arnytron-real)
        )
      ; Notepad
      ("notes" symlink "/notes/list"
        ("list" weblet pages:notepad:page-list)
        ("show/{page}" matching-weblet pages:notepad:page-show)
        ("edit" weblet pages:notepad:page-edit)
        ("edit/{page}" matching-weblet pages:notepad:page-edit)
        ("delete/{page}" matching-weblet pages:notepad:page-delete)
        ("preview" weblet pages:notepad:preview)
        )
      ("media" symlink "/media/list"
        ("list" weblet pages:notepad:media-list)
        ("show/{media}" matching-weblet pages:notepad:media-show)
        ("new" weblet pages:notepad:media-new)
        ("edit/{media}" matching-weblet pages:notepad:media-edit)
        ("delete/{media}" matching-weblet pages:notepad:media-delete)
        )
      ("user" symlink "/user/list"
        ("list" weblet pages:notepad:user-list)
        ("show/{name}" matching-weblet pages:notepad:user-show)
        ("login/{name}" matching-weblet pages:notepad:user-login)
        ("logout" weblet pages:notepad:user-logout)
        ("edit/{name}" matching-weblet pages:notepad:user-edit)
        )
      ))
  ; Sitemap
  (sitemap
    ("Home" "/" #f
      ("About Me" "/AboutMe" #f)
      ("About this Website" "/AboutFeuforeve" #f)
      ("Fonts I made" "/Fonts" #f))
    ("Floraverse" "/Floraverse" #f
      ("Character Generator" "/Floraverse/CharacterGenerator" #t)
      ("Calendar" "/Floraverse/Calendar" #f)
      ("About the character generator" "/Floraverse/AboutCharacterGenerator" #f)
      )
    ("Yggdrasil" "/Yggdrasil" #t
      ("About the Yggdrasil generator" "/Yggdrasil/About" #f)
      )
    ("Flag Generator" "/FlagGenerator" #f
      ("About the flag generator" "/FlagGenerator/About" #f)
      )
    ("Daily Island" "/DailyIsland" #f
      ("Archives" "/DailyIsland/Archives" #f)
      ("About" "/DailyIsland/About" #f)
      )
    ("Miscellaneous Generators" "/Generators" #f
      ("Color Scheme" "/Generators/ColorScheme" #f)
      ("Pictogrammic Adventurer" "/Generators/PictogrammicAdventurer" #t)
      ("Phonagen" "/Generators/Phonagen" #f)
      ("Un Village en France" "/Generators/GenerCommunes" #f)
      ("Road Maps" "/RoadMap" #t)
      ("Pizzeria" "/Generators/Pizzeria" #t)
      )
    ("ArnYtron3000" "/ArnYtron3000" #t
      ("(texte brut)" "/ArnYtron3000/brut" #t)
      ("(json)" "/ArnYtron3000/json" #t)
      ("Vraie citation" "/ArnYtron3000/vraie" #t)
      ("À propos d'ArnYtron3000" "/ArnYtron3000/About" #t)
      )
    ("Notes" "/notes/list" #t
      (#f "/notes/show" #f)
      (#f "/notes/edit" #f)
      (#f "/notes/delete" #f)
      ("Fichiers" "/media/list" #t)
      (#f "/media/show" #f)
      (#f "/media/new" #f)
      (#f "/media/edit" #f)
      (#f "/media/delete" #f)
      ("Utilisateurs" "/user/list" #t)
      (#f "/user/show" #f)
      (#f "/user/login" #f)
      )
    )
  ; Webcontainer
  (define *webcontainer*
    (make-webcontainer
      #:static
        (make-immutable-hash
          `(("" . "./static")
            ("/media/get" . ,(string-append configuration:notepad:path "/media"))))))
  (webcontainer-add-website! *webcontainer* *website*)
  (webcontainer-set-404-weblet! *webcontainer* pages:not-found)
  (display "Starting server...")(newline)
  (webcontainer-start *webcontainer*))
