{-|
Module      : AWS.Lambda.Events.SQS
Description : Data types for working with SQS events.
Copyright   : (c) Nike, Inc., 2019
License     : BSD3
Maintainer  : nathan.fairhurst@nike.com, fernando.freire@nike.com
Stability   : stable
-}

module AWS.Lambda.Events.SQS (
  Records (..),
  Attributes (..),
  SQSEvent (..)
) where

import Data.Aeson   (FromJSON (..), withObject, (.:))
import Data.Map     (Map)
import Data.Text    (Text)
import GHC.Generics (Generic)

newtype Records = Records {
  Records -> [SQSEvent]
records :: [SQSEvent]
} deriving (Int -> Records -> ShowS
[Records] -> ShowS
Records -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Records] -> ShowS
$cshowList :: [Records] -> ShowS
show :: Records -> String
$cshow :: Records -> String
showsPrec :: Int -> Records -> ShowS
$cshowsPrec :: Int -> Records -> ShowS
Show, Records -> Records -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Records -> Records -> Bool
$c/= :: Records -> Records -> Bool
== :: Records -> Records -> Bool
$c== :: Records -> Records -> Bool
Eq)

instance FromJSON Records where
  parseJSON :: Value -> Parser Records
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Records" forall a b. (a -> b) -> a -> b
$ \Object
v -> [SQSEvent] -> Records
Records forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"Records"

data Attributes = Attributes {
  Attributes -> Text
approximateReceiveCount          :: Text,
  Attributes -> Text
sentTimestamp                    :: Text,
  Attributes -> Text
senderId                         :: Text,
  Attributes -> Text
approximateFirstReceiveTimestamp :: Text
} deriving (Int -> Attributes -> ShowS
[Attributes] -> ShowS
Attributes -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Attributes] -> ShowS
$cshowList :: [Attributes] -> ShowS
show :: Attributes -> String
$cshow :: Attributes -> String
showsPrec :: Int -> Attributes -> ShowS
$cshowsPrec :: Int -> Attributes -> ShowS
Show, Attributes -> Attributes -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attributes -> Attributes -> Bool
$c/= :: Attributes -> Attributes -> Bool
== :: Attributes -> Attributes -> Bool
$c== :: Attributes -> Attributes -> Bool
Eq)

instance FromJSON Attributes where
  parseJSON :: Value -> Parser Attributes
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject String
"Attributes" forall a b. (a -> b) -> a -> b
$ \Object
v ->
    Text -> Text -> Text -> Text -> Attributes
Attributes
      forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ApproximateReceiveCount"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"SentTimestamp"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"SenderId"
      forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"ApproximateFirstReceiveTimestamp"

data SQSEvent = SQSEvent {
  SQSEvent -> Text
messageId         :: Text,
  SQSEvent -> Text
receiptHandle     :: Text,
  SQSEvent -> Text
body              :: Text,
  SQSEvent -> Attributes
attributes        :: Attributes,
  SQSEvent -> Map Text Text
messageAttributes :: Map Text Text,
  SQSEvent -> Text
md5OfBody         :: Text,
  SQSEvent -> Text
eventSource       :: Text,
  SQSEvent -> Text
eventSourceARN    :: Text,
  SQSEvent -> Text
awsRegion         :: Text
} deriving (Int -> SQSEvent -> ShowS
[SQSEvent] -> ShowS
SQSEvent -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SQSEvent] -> ShowS
$cshowList :: [SQSEvent] -> ShowS
show :: SQSEvent -> String
$cshow :: SQSEvent -> String
showsPrec :: Int -> SQSEvent -> ShowS
$cshowsPrec :: Int -> SQSEvent -> ShowS
Show, SQSEvent -> SQSEvent -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SQSEvent -> SQSEvent -> Bool
$c/= :: SQSEvent -> SQSEvent -> Bool
== :: SQSEvent -> SQSEvent -> Bool
$c== :: SQSEvent -> SQSEvent -> Bool
Eq, forall x. Rep SQSEvent x -> SQSEvent
forall x. SQSEvent -> Rep SQSEvent x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SQSEvent x -> SQSEvent
$cfrom :: forall x. SQSEvent -> Rep SQSEvent x
Generic)

instance FromJSON SQSEvent