module Airship.Config
    ( AirshipConfig
    , HeaderInclusion (..)
    , includeTraceHeader
    , includeQuipHeader
    , defaultAirshipConfig
    ) where

import           Lens.Micro (Lens', lens)

-- | An opaque data type encapsulating all Airship-specific configuration options.
--
-- We use lenses to modify 'AirshipConfig' values -- though Airship only depends on the
-- microlens library, its lenses are compatible with Control.Lens.
data AirshipConfig = AirshipConfig
    { AirshipConfig -> HeaderInclusion
_includeTraceHeader :: HeaderInclusion
    , AirshipConfig -> HeaderInclusion
_includeQuipHeader :: HeaderInclusion
    }

data HeaderInclusion = IncludeHeader | OmitHeader deriving (HeaderInclusion -> HeaderInclusion -> Bool
(HeaderInclusion -> HeaderInclusion -> Bool)
-> (HeaderInclusion -> HeaderInclusion -> Bool)
-> Eq HeaderInclusion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeaderInclusion -> HeaderInclusion -> Bool
$c/= :: HeaderInclusion -> HeaderInclusion -> Bool
== :: HeaderInclusion -> HeaderInclusion -> Bool
$c== :: HeaderInclusion -> HeaderInclusion -> Bool
Eq, Int -> HeaderInclusion -> ShowS
[HeaderInclusion] -> ShowS
HeaderInclusion -> String
(Int -> HeaderInclusion -> ShowS)
-> (HeaderInclusion -> String)
-> ([HeaderInclusion] -> ShowS)
-> Show HeaderInclusion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderInclusion] -> ShowS
$cshowList :: [HeaderInclusion] -> ShowS
show :: HeaderInclusion -> String
$cshow :: HeaderInclusion -> String
showsPrec :: Int -> HeaderInclusion -> ShowS
$cshowsPrec :: Int -> HeaderInclusion -> ShowS
Show)

-- | Determines whether or not the @Airship-Trace@ header, which traces the execution of
-- a given request in the Airship decision tree, is included in every HTTP response.
-- While exposing the decision tree is usually innocuous (and makes for significantly easier
-- debugging), you may want to turn it off in certain circumstances.
--
-- Defaults to 'IncludeHeader' (enabled).
includeTraceHeader :: Lens' AirshipConfig HeaderInclusion
includeTraceHeader :: (HeaderInclusion -> f HeaderInclusion)
-> AirshipConfig -> f AirshipConfig
includeTraceHeader = (AirshipConfig -> HeaderInclusion)
-> (AirshipConfig -> HeaderInclusion -> AirshipConfig)
-> Lens AirshipConfig AirshipConfig HeaderInclusion HeaderInclusion
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens AirshipConfig -> HeaderInclusion
_includeTraceHeader (\AirshipConfig
s HeaderInclusion
n -> AirshipConfig
s { _includeTraceHeader :: HeaderInclusion
_includeTraceHeader = HeaderInclusion
n })

-- | Determines whether or not the @Airship-Quip@ header, which includes a pithy
-- quote in your response headers, is included in every HTTP response.
--
-- Defaults to 'IncludeHeader' (enabled).
includeQuipHeader :: Lens' AirshipConfig HeaderInclusion
includeQuipHeader :: (HeaderInclusion -> f HeaderInclusion)
-> AirshipConfig -> f AirshipConfig
includeQuipHeader = (AirshipConfig -> HeaderInclusion)
-> (AirshipConfig -> HeaderInclusion -> AirshipConfig)
-> Lens AirshipConfig AirshipConfig HeaderInclusion HeaderInclusion
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens AirshipConfig -> HeaderInclusion
_includeQuipHeader (\AirshipConfig
s HeaderInclusion
n -> AirshipConfig
s { _includeQuipHeader :: HeaderInclusion
_includeQuipHeader = HeaderInclusion
n })

-- | The default configuration. Use this, in conjunction with the lenses declared
-- above, to get and modify an 'AirshipConfig' to pass to 'resourceToWai'.
defaultAirshipConfig :: AirshipConfig
defaultAirshipConfig :: AirshipConfig
defaultAirshipConfig = HeaderInclusion -> HeaderInclusion -> AirshipConfig
AirshipConfig HeaderInclusion
IncludeHeader HeaderInclusion
IncludeHeader