content: {-# options -fno-warn-orphans #-}
  {-# LANGUAGE QuasiQuotes, TemplateHaskell #-}
  module Perf.Web.Foundation where
  
  import Data.Coerce
  import Data.Text (Text)
  import qualified Data.Text as T
  import Yesod
  import Perf.Types.Web
  import Perf.Types.Prim
  
  mkYesodData "App" [parseRoutes|
    / HomeR GET
    /branches BranchesR GET
    /branch/#Text BranchR GET
    /branch/#Text/#Hash BranchCommitR GET
    /commit/#Hash CommitR GET
    /compare/#Hash/#Hash CompareCommitsR GET
    /hooks/update ReceiverR POST
  |]
  
  instance Yesod App where
    makeSessionBackend _ = return Nothing
  
  instance YesodBreadcrumbs App where
    breadcrumb r =
      case r of
        HomeR -> return ("Home",Nothing)
        BranchesR -> return ("Branches",Just HomeR)
        BranchR name -> return (name, Just BranchesR)
        CommitR hash -> return (coerce hash, Just HomeR)
        CompareCommitsR hash0 hash1 ->
          let short x = T.take 8 $ coerce x
          in return ("Compare " <> short hash0 <> " .. " <> short hash1, Just HomeR)
        BranchCommitR branch commit -> return (coerce commit, Just $ BranchR branch)
        ReceiverR -> return ("Webhook Receiver", Nothing)
  