{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.Greengrass.Types.Subscription
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Greengrass.Types.Subscription where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Information about a subscription.
--
-- /See:/ 'newSubscription' smart constructor.
data Subscription = Subscription'
  { -- | Where the message is sent to. Can be a thing ARN, a Lambda function ARN,
    -- a connector ARN, \'cloud\' (which represents the AWS IoT cloud), or
    -- \'GGShadowService\'.
    Subscription -> Text
target :: Prelude.Text,
    -- | A descriptive or arbitrary ID for the subscription. This value must be
    -- unique within the subscription definition version. Max length is 128
    -- characters with pattern \'\'[a-zA-Z0-9:_-]+\'\'.
    Subscription -> Text
id :: Prelude.Text,
    -- | The MQTT topic used to route the message.
    Subscription -> Text
subject :: Prelude.Text,
    -- | The source of the subscription. Can be a thing ARN, a Lambda function
    -- ARN, a connector ARN, \'cloud\' (which represents the AWS IoT cloud), or
    -- \'GGShadowService\'.
    Subscription -> Text
source :: Prelude.Text
  }
  deriving (Subscription -> Subscription -> Bool
(Subscription -> Subscription -> Bool)
-> (Subscription -> Subscription -> Bool) -> Eq Subscription
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Subscription -> Subscription -> Bool
$c/= :: Subscription -> Subscription -> Bool
== :: Subscription -> Subscription -> Bool
$c== :: Subscription -> Subscription -> Bool
Prelude.Eq, ReadPrec [Subscription]
ReadPrec Subscription
Int -> ReadS Subscription
ReadS [Subscription]
(Int -> ReadS Subscription)
-> ReadS [Subscription]
-> ReadPrec Subscription
-> ReadPrec [Subscription]
-> Read Subscription
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Subscription]
$creadListPrec :: ReadPrec [Subscription]
readPrec :: ReadPrec Subscription
$creadPrec :: ReadPrec Subscription
readList :: ReadS [Subscription]
$creadList :: ReadS [Subscription]
readsPrec :: Int -> ReadS Subscription
$creadsPrec :: Int -> ReadS Subscription
Prelude.Read, Int -> Subscription -> ShowS
[Subscription] -> ShowS
Subscription -> String
(Int -> Subscription -> ShowS)
-> (Subscription -> String)
-> ([Subscription] -> ShowS)
-> Show Subscription
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Subscription] -> ShowS
$cshowList :: [Subscription] -> ShowS
show :: Subscription -> String
$cshow :: Subscription -> String
showsPrec :: Int -> Subscription -> ShowS
$cshowsPrec :: Int -> Subscription -> ShowS
Prelude.Show, (forall x. Subscription -> Rep Subscription x)
-> (forall x. Rep Subscription x -> Subscription)
-> Generic Subscription
forall x. Rep Subscription x -> Subscription
forall x. Subscription -> Rep Subscription x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Subscription x -> Subscription
$cfrom :: forall x. Subscription -> Rep Subscription x
Prelude.Generic)

-- |
-- Create a value of 'Subscription' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'target', 'subscription_target' - Where the message is sent to. Can be a thing ARN, a Lambda function ARN,
-- a connector ARN, \'cloud\' (which represents the AWS IoT cloud), or
-- \'GGShadowService\'.
--
-- 'id', 'subscription_id' - A descriptive or arbitrary ID for the subscription. This value must be
-- unique within the subscription definition version. Max length is 128
-- characters with pattern \'\'[a-zA-Z0-9:_-]+\'\'.
--
-- 'subject', 'subscription_subject' - The MQTT topic used to route the message.
--
-- 'source', 'subscription_source' - The source of the subscription. Can be a thing ARN, a Lambda function
-- ARN, a connector ARN, \'cloud\' (which represents the AWS IoT cloud), or
-- \'GGShadowService\'.
newSubscription ::
  -- | 'target'
  Prelude.Text ->
  -- | 'id'
  Prelude.Text ->
  -- | 'subject'
  Prelude.Text ->
  -- | 'source'
  Prelude.Text ->
  Subscription
newSubscription :: Text -> Text -> Text -> Text -> Subscription
newSubscription Text
pTarget_ Text
pId_ Text
pSubject_ Text
pSource_ =
  Subscription' :: Text -> Text -> Text -> Text -> Subscription
Subscription'
    { $sel:target:Subscription' :: Text
target = Text
pTarget_,
      $sel:id:Subscription' :: Text
id = Text
pId_,
      $sel:subject:Subscription' :: Text
subject = Text
pSubject_,
      $sel:source:Subscription' :: Text
source = Text
pSource_
    }

-- | Where the message is sent to. Can be a thing ARN, a Lambda function ARN,
-- a connector ARN, \'cloud\' (which represents the AWS IoT cloud), or
-- \'GGShadowService\'.
subscription_target :: Lens.Lens' Subscription Prelude.Text
subscription_target :: (Text -> f Text) -> Subscription -> f Subscription
subscription_target = (Subscription -> Text)
-> (Subscription -> Text -> Subscription)
-> Lens Subscription Subscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Text
target :: Text
$sel:target:Subscription' :: Subscription -> Text
target} -> Text
target) (\s :: Subscription
s@Subscription' {} Text
a -> Subscription
s {$sel:target:Subscription' :: Text
target = Text
a} :: Subscription)

-- | A descriptive or arbitrary ID for the subscription. This value must be
-- unique within the subscription definition version. Max length is 128
-- characters with pattern \'\'[a-zA-Z0-9:_-]+\'\'.
subscription_id :: Lens.Lens' Subscription Prelude.Text
subscription_id :: (Text -> f Text) -> Subscription -> f Subscription
subscription_id = (Subscription -> Text)
-> (Subscription -> Text -> Subscription)
-> Lens Subscription Subscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Text
id :: Text
$sel:id:Subscription' :: Subscription -> Text
id} -> Text
id) (\s :: Subscription
s@Subscription' {} Text
a -> Subscription
s {$sel:id:Subscription' :: Text
id = Text
a} :: Subscription)

-- | The MQTT topic used to route the message.
subscription_subject :: Lens.Lens' Subscription Prelude.Text
subscription_subject :: (Text -> f Text) -> Subscription -> f Subscription
subscription_subject = (Subscription -> Text)
-> (Subscription -> Text -> Subscription)
-> Lens Subscription Subscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Text
subject :: Text
$sel:subject:Subscription' :: Subscription -> Text
subject} -> Text
subject) (\s :: Subscription
s@Subscription' {} Text
a -> Subscription
s {$sel:subject:Subscription' :: Text
subject = Text
a} :: Subscription)

-- | The source of the subscription. Can be a thing ARN, a Lambda function
-- ARN, a connector ARN, \'cloud\' (which represents the AWS IoT cloud), or
-- \'GGShadowService\'.
subscription_source :: Lens.Lens' Subscription Prelude.Text
subscription_source :: (Text -> f Text) -> Subscription -> f Subscription
subscription_source = (Subscription -> Text)
-> (Subscription -> Text -> Subscription)
-> Lens Subscription Subscription Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Subscription' {Text
source :: Text
$sel:source:Subscription' :: Subscription -> Text
source} -> Text
source) (\s :: Subscription
s@Subscription' {} Text
a -> Subscription
s {$sel:source:Subscription' :: Text
source = Text
a} :: Subscription)

instance Core.FromJSON Subscription where
  parseJSON :: Value -> Parser Subscription
parseJSON =
    String
-> (Object -> Parser Subscription) -> Value -> Parser Subscription
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Subscription"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> Subscription
Subscription'
            (Text -> Text -> Text -> Text -> Subscription)
-> Parser Text -> Parser (Text -> Text -> Text -> Subscription)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Target")
            Parser (Text -> Text -> Text -> Subscription)
-> Parser Text -> Parser (Text -> Text -> Subscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Id")
            Parser (Text -> Text -> Subscription)
-> Parser Text -> Parser (Text -> Subscription)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Subject")
            Parser (Text -> Subscription) -> Parser Text -> Parser Subscription
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Source")
      )

instance Prelude.Hashable Subscription

instance Prelude.NFData Subscription

instance Core.ToJSON Subscription where
  toJSON :: Subscription -> Value
toJSON Subscription' {Text
source :: Text
subject :: Text
id :: Text
target :: Text
$sel:source:Subscription' :: Subscription -> Text
$sel:subject:Subscription' :: Subscription -> Text
$sel:id:Subscription' :: Subscription -> Text
$sel:target:Subscription' :: Subscription -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Target" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
target),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Id" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
id),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Subject" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
subject),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Source" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
source)
          ]
      )