{-# 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.SSMIncidents.Types.RelatedItem
-- 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.SSMIncidents.Types.RelatedItem where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.SSMIncidents.Types.ItemIdentifier

-- | Resources that responders use to triage and mitigate the incident.
--
-- /See:/ 'newRelatedItem' smart constructor.
data RelatedItem = RelatedItem'
  { -- | The title of the related item.
    RelatedItem -> Maybe Text
title :: Prelude.Maybe Prelude.Text,
    -- | Details about the related item.
    RelatedItem -> ItemIdentifier
identifier :: ItemIdentifier
  }
  deriving (RelatedItem -> RelatedItem -> Bool
(RelatedItem -> RelatedItem -> Bool)
-> (RelatedItem -> RelatedItem -> Bool) -> Eq RelatedItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RelatedItem -> RelatedItem -> Bool
$c/= :: RelatedItem -> RelatedItem -> Bool
== :: RelatedItem -> RelatedItem -> Bool
$c== :: RelatedItem -> RelatedItem -> Bool
Prelude.Eq, ReadPrec [RelatedItem]
ReadPrec RelatedItem
Int -> ReadS RelatedItem
ReadS [RelatedItem]
(Int -> ReadS RelatedItem)
-> ReadS [RelatedItem]
-> ReadPrec RelatedItem
-> ReadPrec [RelatedItem]
-> Read RelatedItem
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RelatedItem]
$creadListPrec :: ReadPrec [RelatedItem]
readPrec :: ReadPrec RelatedItem
$creadPrec :: ReadPrec RelatedItem
readList :: ReadS [RelatedItem]
$creadList :: ReadS [RelatedItem]
readsPrec :: Int -> ReadS RelatedItem
$creadsPrec :: Int -> ReadS RelatedItem
Prelude.Read, Int -> RelatedItem -> ShowS
[RelatedItem] -> ShowS
RelatedItem -> String
(Int -> RelatedItem -> ShowS)
-> (RelatedItem -> String)
-> ([RelatedItem] -> ShowS)
-> Show RelatedItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RelatedItem] -> ShowS
$cshowList :: [RelatedItem] -> ShowS
show :: RelatedItem -> String
$cshow :: RelatedItem -> String
showsPrec :: Int -> RelatedItem -> ShowS
$cshowsPrec :: Int -> RelatedItem -> ShowS
Prelude.Show, (forall x. RelatedItem -> Rep RelatedItem x)
-> (forall x. Rep RelatedItem x -> RelatedItem)
-> Generic RelatedItem
forall x. Rep RelatedItem x -> RelatedItem
forall x. RelatedItem -> Rep RelatedItem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RelatedItem x -> RelatedItem
$cfrom :: forall x. RelatedItem -> Rep RelatedItem x
Prelude.Generic)

-- |
-- Create a value of 'RelatedItem' 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:
--
-- 'title', 'relatedItem_title' - The title of the related item.
--
-- 'identifier', 'relatedItem_identifier' - Details about the related item.
newRelatedItem ::
  -- | 'identifier'
  ItemIdentifier ->
  RelatedItem
newRelatedItem :: ItemIdentifier -> RelatedItem
newRelatedItem ItemIdentifier
pIdentifier_ =
  RelatedItem' :: Maybe Text -> ItemIdentifier -> RelatedItem
RelatedItem'
    { $sel:title:RelatedItem' :: Maybe Text
title = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:identifier:RelatedItem' :: ItemIdentifier
identifier = ItemIdentifier
pIdentifier_
    }

-- | The title of the related item.
relatedItem_title :: Lens.Lens' RelatedItem (Prelude.Maybe Prelude.Text)
relatedItem_title :: (Maybe Text -> f (Maybe Text)) -> RelatedItem -> f RelatedItem
relatedItem_title = (RelatedItem -> Maybe Text)
-> (RelatedItem -> Maybe Text -> RelatedItem)
-> Lens RelatedItem RelatedItem (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelatedItem' {Maybe Text
title :: Maybe Text
$sel:title:RelatedItem' :: RelatedItem -> Maybe Text
title} -> Maybe Text
title) (\s :: RelatedItem
s@RelatedItem' {} Maybe Text
a -> RelatedItem
s {$sel:title:RelatedItem' :: Maybe Text
title = Maybe Text
a} :: RelatedItem)

-- | Details about the related item.
relatedItem_identifier :: Lens.Lens' RelatedItem ItemIdentifier
relatedItem_identifier :: (ItemIdentifier -> f ItemIdentifier)
-> RelatedItem -> f RelatedItem
relatedItem_identifier = (RelatedItem -> ItemIdentifier)
-> (RelatedItem -> ItemIdentifier -> RelatedItem)
-> Lens RelatedItem RelatedItem ItemIdentifier ItemIdentifier
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelatedItem' {ItemIdentifier
identifier :: ItemIdentifier
$sel:identifier:RelatedItem' :: RelatedItem -> ItemIdentifier
identifier} -> ItemIdentifier
identifier) (\s :: RelatedItem
s@RelatedItem' {} ItemIdentifier
a -> RelatedItem
s {$sel:identifier:RelatedItem' :: ItemIdentifier
identifier = ItemIdentifier
a} :: RelatedItem)

instance Core.FromJSON RelatedItem where
  parseJSON :: Value -> Parser RelatedItem
parseJSON =
    String
-> (Object -> Parser RelatedItem) -> Value -> Parser RelatedItem
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RelatedItem"
      ( \Object
x ->
          Maybe Text -> ItemIdentifier -> RelatedItem
RelatedItem'
            (Maybe Text -> ItemIdentifier -> RelatedItem)
-> Parser (Maybe Text) -> Parser (ItemIdentifier -> RelatedItem)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"title")
            Parser (ItemIdentifier -> RelatedItem)
-> Parser ItemIdentifier -> Parser RelatedItem
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser ItemIdentifier
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"identifier")
      )

instance Prelude.Hashable RelatedItem

instance Prelude.NFData RelatedItem

instance Core.ToJSON RelatedItem where
  toJSON :: RelatedItem -> Value
toJSON RelatedItem' {Maybe Text
ItemIdentifier
identifier :: ItemIdentifier
title :: Maybe Text
$sel:identifier:RelatedItem' :: RelatedItem -> ItemIdentifier
$sel:title:RelatedItem' :: RelatedItem -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"title" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
title,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"identifier" Text -> ItemIdentifier -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= ItemIdentifier
identifier)
          ]
      )