module Network.OAuth2.Experiment.Flows.AuthorizationRequest where

import Data.Map.Strict (Map)
import Data.Map.Strict qualified as Map
import Data.Set (Set)
import Data.Text.Lazy (Text)
import Network.OAuth2.Experiment.Types

-------------------------------------------------------------------------------
--                           Authorization Request                           --
-------------------------------------------------------------------------------

data AuthorizationRequestParam = AuthorizationRequestParam
  { AuthorizationRequestParam -> Set Scope
arScope :: Set Scope
  , AuthorizationRequestParam -> AuthorizeState
arState :: AuthorizeState
  , AuthorizationRequestParam -> ClientId
arClientId :: ClientId
  , AuthorizationRequestParam -> Maybe RedirectUri
arRedirectUri :: Maybe RedirectUri
  , AuthorizationRequestParam -> ResponseType
arResponseType :: ResponseType
  -- ^ It could be optional there is only one redirect_uri registered.
  -- See: https://www.rfc-editor.org/rfc/rfc6749#section-3.1.2.3
  , AuthorizationRequestParam -> Map Text Text
arExtraParams :: Map Text Text
  }

instance ToQueryParam AuthorizationRequestParam where
  toQueryParam :: AuthorizationRequestParam -> Map Text Text
toQueryParam AuthorizationRequestParam {Maybe RedirectUri
Map Text Text
Set Scope
AuthorizeState
ClientId
ResponseType
arScope :: AuthorizationRequestParam -> Set Scope
arState :: AuthorizationRequestParam -> AuthorizeState
arClientId :: AuthorizationRequestParam -> ClientId
arRedirectUri :: AuthorizationRequestParam -> Maybe RedirectUri
arResponseType :: AuthorizationRequestParam -> ResponseType
arExtraParams :: AuthorizationRequestParam -> Map Text Text
arScope :: Set Scope
arState :: AuthorizeState
arClientId :: ClientId
arRedirectUri :: Maybe RedirectUri
arResponseType :: ResponseType
arExtraParams :: Map Text Text
..} =
    [Map Text Text] -> Map Text Text
forall (f :: * -> *) k a.
(Foldable f, Ord k) =>
f (Map k a) -> Map k a
Map.unions
      [ ResponseType -> Map Text Text
forall a. ToQueryParam a => a -> Map Text Text
toQueryParam ResponseType
arResponseType
      , Set Scope -> Map Text Text
forall a. ToQueryParam a => a -> Map Text Text
toQueryParam Set Scope
arScope
      , ClientId -> Map Text Text
forall a. ToQueryParam a => a -> Map Text Text
toQueryParam ClientId
arClientId
      , AuthorizeState -> Map Text Text
forall a. ToQueryParam a => a -> Map Text Text
toQueryParam AuthorizeState
arState
      , Maybe RedirectUri -> Map Text Text
forall a. ToQueryParam a => a -> Map Text Text
toQueryParam Maybe RedirectUri
arRedirectUri
      , Map Text Text
arExtraParams
      ]