{-# LANGUAGE FlexibleInstances      #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeSynonymInstances   #-}
{-# LANGUAGE MultiParamTypeClasses  #-}

module Zero.Registration.API
  (
    RegistrationViewAPI
  , RegistrationAPI

  , registrationViewAPI
  , registrationAPI
  ) where

import           Data.Proxy (Proxy(..))
import           Servant.API
import           Zero.Account.Verification.Internal
import           Zero.Registration.Internal
import           Zero.ContentTypes
import           Zero.View hiding (Header)

------------------------------------------------------------------------------

type RegistrationViewAPI =
       -- Verification URL route (sent in email)
       "recovery_email" :> "verify"
       :> Capture "code" VerificationCode
       :> Get '[HTMLLucid] (View Verification)

type RegistrationAPI =
       -- Registration route
       "register"
       :> ReqBody '[JSON] Registration
       :> Post '[JSON] RegistrationResult

        -- The route which sends the verification code to the server
  :<|> "recovery_email" :> "send_code"
       :> ReqBody '[PlainText] VerificationCode
       :> Post '[JSON] ()

  --      -- Re-send the verification code (requires an unverified session)
  -- :<|> SessionToken :> "recovery_email" :> "resend_code"
  --      :> Post '[JSON] ()

------------------------------------------------------------------------------

registrationViewAPI :: Proxy RegistrationViewAPI
registrationViewAPI = Proxy

registrationAPI :: Proxy RegistrationAPI
registrationAPI = Proxy
