content: {-# LANGUAGE EmptyCase #-}
  {-# LANGUAGE FlexibleContexts #-}
  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE GADTs #-}
  {-# LANGUAGE KindSignatures #-}
  {-# LANGUAGE LambdaCase #-}
  {-# LANGUAGE MultiParamTypeClasses #-}
  {-# LANGUAGE OverloadedStrings #-}
  {-# LANGUAGE RankNTypes #-}
  {-# LANGUAGE TemplateHaskell #-}
  {-# LANGUAGE TypeFamilies #-}
  
  module Common.Route where
  
  {- -- You will probably want these imports for composing Encoders.
  import Prelude hiding (id, (.))
  import Control.Category
  -}
  
  import Data.Functor.Identity
  import Data.Text (Text)
  import Obelisk.Route
  import Obelisk.Route.TH
  import Strato.Lite.Rest.Api
  
  data BackendRoute :: * -> * where
    -- | Used to handle unparseable routes.
    BackendRoute_Missing :: BackendRoute ()
    BackendRoute_GetNodes :: BackendRoute (Map Text ThreadResultMap)
  
  -- You can define any routes that will be handled specially by the backend here.
  -- i.e. These do not serve the frontend, but do something different, such as serving static files.
  
  data FrontendRoute :: * -> * where
    FrontendRoute_Main :: FrontendRoute ()
  
  -- This type is used to define frontend routes, i.e. ones for which the backend will serve the frontend.
  
  fullRouteEncoder ::
    Encoder (Either Text) Identity (R (FullRoute BackendRoute FrontendRoute)) PageName
  fullRouteEncoder =
    mkFullRouteEncoder
      (FullRoute_Backend BackendRoute_Missing :/ ()) -- nobody will ever think to look here
      ( \case
          BackendRoute_Missing -> PathSegment "missing" $ unitEncoder mempty
      )
      ( \case
          FrontendRoute_Main -> PathEnd $ unitEncoder mempty
      )
  
  concat
    <$> mapM
      deriveRouteComponent
      [ ''BackendRoute,
        ''FrontendRoute
      ]
  