{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Greengrass.Types.Subscription where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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'
    { $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 :: Lens' Subscription Text
subscription_target = 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 :: Lens' Subscription Text
subscription_id = 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 :: Lens' Subscription Text
subscription_subject = 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 :: Lens' Subscription Text
subscription_source = 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 Data.FromJSON Subscription where
  parseJSON :: Value -> Parser Subscription
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Subscription"
      ( \Object
x ->
          Text -> Text -> Text -> Text -> Subscription
Subscription'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Target")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Id")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Subject")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Source")
      )

instance Prelude.Hashable Subscription where
  hashWithSalt :: Int -> Subscription -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
target
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
id
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
subject
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
source

instance Prelude.NFData Subscription where
  rnf :: Subscription -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
target
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
id
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
subject
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
source

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"Target" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
target),
            forall a. a -> Maybe a
Prelude.Just (Key
"Id" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
id),
            forall a. a -> Maybe a
Prelude.Just (Key
"Subject" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
subject),
            forall a. a -> Maybe a
Prelude.Just (Key
"Source" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
source)
          ]
      )