{-# 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.Pinpoint.Types.TagsModel
-- 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.Pinpoint.Types.TagsModel where

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

-- | Specifies the tags (keys and values) for an application, campaign,
-- message template, or segment.
--
-- /See:/ 'newTagsModel' smart constructor.
data TagsModel = TagsModel'
  { -- | A string-to-string map of key-value pairs that defines the tags for an
    -- application, campaign, message template, or segment. Each of these
    -- resources can have a maximum of 50 tags.
    --
    -- Each tag consists of a required tag key and an associated tag value. The
    -- maximum length of a tag key is 128 characters. The maximum length of a
    -- tag value is 256 characters.
    TagsModel -> HashMap Text Text
tags :: Prelude.HashMap Prelude.Text Prelude.Text
  }
  deriving (TagsModel -> TagsModel -> Bool
(TagsModel -> TagsModel -> Bool)
-> (TagsModel -> TagsModel -> Bool) -> Eq TagsModel
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TagsModel -> TagsModel -> Bool
$c/= :: TagsModel -> TagsModel -> Bool
== :: TagsModel -> TagsModel -> Bool
$c== :: TagsModel -> TagsModel -> Bool
Prelude.Eq, ReadPrec [TagsModel]
ReadPrec TagsModel
Int -> ReadS TagsModel
ReadS [TagsModel]
(Int -> ReadS TagsModel)
-> ReadS [TagsModel]
-> ReadPrec TagsModel
-> ReadPrec [TagsModel]
-> Read TagsModel
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TagsModel]
$creadListPrec :: ReadPrec [TagsModel]
readPrec :: ReadPrec TagsModel
$creadPrec :: ReadPrec TagsModel
readList :: ReadS [TagsModel]
$creadList :: ReadS [TagsModel]
readsPrec :: Int -> ReadS TagsModel
$creadsPrec :: Int -> ReadS TagsModel
Prelude.Read, Int -> TagsModel -> ShowS
[TagsModel] -> ShowS
TagsModel -> String
(Int -> TagsModel -> ShowS)
-> (TagsModel -> String)
-> ([TagsModel] -> ShowS)
-> Show TagsModel
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TagsModel] -> ShowS
$cshowList :: [TagsModel] -> ShowS
show :: TagsModel -> String
$cshow :: TagsModel -> String
showsPrec :: Int -> TagsModel -> ShowS
$cshowsPrec :: Int -> TagsModel -> ShowS
Prelude.Show, (forall x. TagsModel -> Rep TagsModel x)
-> (forall x. Rep TagsModel x -> TagsModel) -> Generic TagsModel
forall x. Rep TagsModel x -> TagsModel
forall x. TagsModel -> Rep TagsModel x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep TagsModel x -> TagsModel
$cfrom :: forall x. TagsModel -> Rep TagsModel x
Prelude.Generic)

-- |
-- Create a value of 'TagsModel' 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:
--
-- 'tags', 'tagsModel_tags' - A string-to-string map of key-value pairs that defines the tags for an
-- application, campaign, message template, or segment. Each of these
-- resources can have a maximum of 50 tags.
--
-- Each tag consists of a required tag key and an associated tag value. The
-- maximum length of a tag key is 128 characters. The maximum length of a
-- tag value is 256 characters.
newTagsModel ::
  TagsModel
newTagsModel :: TagsModel
newTagsModel = TagsModel' :: HashMap Text Text -> TagsModel
TagsModel' {$sel:tags:TagsModel' :: HashMap Text Text
tags = HashMap Text Text
forall a. Monoid a => a
Prelude.mempty}

-- | A string-to-string map of key-value pairs that defines the tags for an
-- application, campaign, message template, or segment. Each of these
-- resources can have a maximum of 50 tags.
--
-- Each tag consists of a required tag key and an associated tag value. The
-- maximum length of a tag key is 128 characters. The maximum length of a
-- tag value is 256 characters.
tagsModel_tags :: Lens.Lens' TagsModel (Prelude.HashMap Prelude.Text Prelude.Text)
tagsModel_tags :: (HashMap Text Text -> f (HashMap Text Text))
-> TagsModel -> f TagsModel
tagsModel_tags = (TagsModel -> HashMap Text Text)
-> (TagsModel -> HashMap Text Text -> TagsModel)
-> Lens TagsModel TagsModel (HashMap Text Text) (HashMap Text Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\TagsModel' {HashMap Text Text
tags :: HashMap Text Text
$sel:tags:TagsModel' :: TagsModel -> HashMap Text Text
tags} -> HashMap Text Text
tags) (\s :: TagsModel
s@TagsModel' {} HashMap Text Text
a -> TagsModel
s {$sel:tags:TagsModel' :: HashMap Text Text
tags = HashMap Text Text
a} :: TagsModel) ((HashMap Text Text -> f (HashMap Text Text))
 -> TagsModel -> f TagsModel)
-> ((HashMap Text Text -> f (HashMap Text Text))
    -> HashMap Text Text -> f (HashMap Text Text))
-> (HashMap Text Text -> f (HashMap Text Text))
-> TagsModel
-> f TagsModel
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (HashMap Text Text -> f (HashMap Text Text))
-> HashMap Text Text -> f (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON TagsModel where
  parseJSON :: Value -> Parser TagsModel
parseJSON =
    String -> (Object -> Parser TagsModel) -> Value -> Parser TagsModel
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"TagsModel"
      ( \Object
x ->
          HashMap Text Text -> TagsModel
TagsModel'
            (HashMap Text Text -> TagsModel)
-> Parser (HashMap Text Text) -> Parser TagsModel
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe (HashMap Text Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"tags" Parser (Maybe (HashMap Text Text))
-> HashMap Text Text -> Parser (HashMap Text Text)
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= HashMap Text Text
forall a. Monoid a => a
Prelude.mempty)
      )

instance Prelude.Hashable TagsModel

instance Prelude.NFData TagsModel

instance Core.ToJSON TagsModel where
  toJSON :: TagsModel -> Value
toJSON TagsModel' {HashMap Text Text
tags :: HashMap Text Text
$sel:tags:TagsModel' :: TagsModel -> HashMap Text 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
"tags" Text -> HashMap Text Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= HashMap Text Text
tags)]
      )