module WikiMusic.SSR.Servant.ApiSpec (WikiMusicSSRServant) where

import Data.UUID (UUID)
import Relude
import Servant
import Servant.HTML.Blaze as ServantBlaze
import Servant.Multipart
import Text.Blaze.Html as Html
import WikiMusic.SSR.Backend.Rest ()
import WikiMusic.SSR.View.Html ()

type WikiMusicSSRServant =
  Get '[ServantBlaze.HTML] NoContent
    :<|> "artists"
      :> WithCookie
      :> QueryParam "sort-order" Text
      :> QueryParam "limit" Int
      :> QueryParam "offset" Int
      :> GetHtml
    :<|> "artists" :> WithCookie :> Capture "identifier" UUID :> GetHtml
    :<|> "artists" :> "create" :> WithCookie :> GetHtml
    :<|> "artists" :> "create" :> WithCookie :> PostDataForm
    :<|> "artists" :> "like" :> WithCookie :> WithReferer :> Capture "identifier" UUID :> PostNoFields
    :<|> "artists" :> "dislike" :> WithCookie :> WithReferer :> Capture "identifier" UUID :> PostNoFields
    :<|> "genres"
      :> WithCookie
      :> QueryParam "sort-order" Text
      :> QueryParam "limit" Int
      :> QueryParam "offset" Int
      :> GetHtml
    :<|> "genres" :> WithCookie :> Capture "identifier" UUID :> GetHtml
    :<|> "genres" :> "create" :> WithCookie :> GetHtml
    :<|> "songs"
      :> WithCookie
      :> QueryParam "sort-order" Text
      :> QueryParam "limit" Int
      :> QueryParam "offset" Int
      :> GetHtml
    :<|> "songs" :> WithCookie :> Capture "identifier" UUID :> GetHtml
    :<|> "songs" :> "create" :> WithCookie :> GetHtml
    :<|> "user-preferences" :> "locale" :> WithReferer :> CookieForm
    :<|> "user-preferences" :> "artist-sorting" :> WithReferer :> CookieForm
    :<|> "user-preferences" :> "genre-sorting" :> WithReferer :> CookieForm
    :<|> "user-preferences" :> "song-sorting" :> WithReferer :> CookieForm
    :<|> "user-preferences" :> "dark-mode" :> WithReferer :> CookieForm
    :<|> "user-preferences" :> "song-ascii-size" :> WithReferer :> CookieForm
    :<|> "user-preferences" :> "palette" :> WithReferer :> CookieForm
    :<|> "login" :> WithCookie :> GetHtml
    :<|> "login" :> CookieForm

type PostDataForm =
  MultipartForm Mem (MultipartData Mem)
    :> Post '[ServantBlaze.HTML] (Headers '[Header "Location" Text] NoContent)

type PostNoFields = Post '[ServantBlaze.HTML] (Headers '[Header "Location" Text] NoContent)

type CookieForm =
  MultipartForm Mem (MultipartData Mem)
    :> Post '[ServantBlaze.HTML] (Headers '[Header "Set-Cookie" Text, Header "Location" Text] NoContent)

type GetHtml = Get '[ServantBlaze.HTML] Html

type WithCookie = Header "cookie" Text

type WithReferer = Header "referer" Text