{-# 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.LicenseManager.Types.Metadata
-- 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.LicenseManager.Types.Metadata where

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

-- | Describes key\/value pairs.
--
-- /See:/ 'newMetadata' smart constructor.
data Metadata = Metadata'
  { -- | The value.
    Metadata -> Maybe Text
value :: Prelude.Maybe Prelude.Text,
    -- | The key name.
    Metadata -> Maybe Text
name :: Prelude.Maybe Prelude.Text
  }
  deriving (Metadata -> Metadata -> Bool
(Metadata -> Metadata -> Bool)
-> (Metadata -> Metadata -> Bool) -> Eq Metadata
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Metadata -> Metadata -> Bool
$c/= :: Metadata -> Metadata -> Bool
== :: Metadata -> Metadata -> Bool
$c== :: Metadata -> Metadata -> Bool
Prelude.Eq, ReadPrec [Metadata]
ReadPrec Metadata
Int -> ReadS Metadata
ReadS [Metadata]
(Int -> ReadS Metadata)
-> ReadS [Metadata]
-> ReadPrec Metadata
-> ReadPrec [Metadata]
-> Read Metadata
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Metadata]
$creadListPrec :: ReadPrec [Metadata]
readPrec :: ReadPrec Metadata
$creadPrec :: ReadPrec Metadata
readList :: ReadS [Metadata]
$creadList :: ReadS [Metadata]
readsPrec :: Int -> ReadS Metadata
$creadsPrec :: Int -> ReadS Metadata
Prelude.Read, Int -> Metadata -> ShowS
[Metadata] -> ShowS
Metadata -> String
(Int -> Metadata -> ShowS)
-> (Metadata -> String) -> ([Metadata] -> ShowS) -> Show Metadata
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Metadata] -> ShowS
$cshowList :: [Metadata] -> ShowS
show :: Metadata -> String
$cshow :: Metadata -> String
showsPrec :: Int -> Metadata -> ShowS
$cshowsPrec :: Int -> Metadata -> ShowS
Prelude.Show, (forall x. Metadata -> Rep Metadata x)
-> (forall x. Rep Metadata x -> Metadata) -> Generic Metadata
forall x. Rep Metadata x -> Metadata
forall x. Metadata -> Rep Metadata x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Metadata x -> Metadata
$cfrom :: forall x. Metadata -> Rep Metadata x
Prelude.Generic)

-- |
-- Create a value of 'Metadata' 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:
--
-- 'value', 'metadata_value' - The value.
--
-- 'name', 'metadata_name' - The key name.
newMetadata ::
  Metadata
newMetadata :: Metadata
newMetadata =
  Metadata' :: Maybe Text -> Maybe Text -> Metadata
Metadata'
    { $sel:value:Metadata' :: Maybe Text
value = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Metadata' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The value.
metadata_value :: Lens.Lens' Metadata (Prelude.Maybe Prelude.Text)
metadata_value :: (Maybe Text -> f (Maybe Text)) -> Metadata -> f Metadata
metadata_value = (Metadata -> Maybe Text)
-> (Metadata -> Maybe Text -> Metadata)
-> Lens Metadata Metadata (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metadata' {Maybe Text
value :: Maybe Text
$sel:value:Metadata' :: Metadata -> Maybe Text
value} -> Maybe Text
value) (\s :: Metadata
s@Metadata' {} Maybe Text
a -> Metadata
s {$sel:value:Metadata' :: Maybe Text
value = Maybe Text
a} :: Metadata)

-- | The key name.
metadata_name :: Lens.Lens' Metadata (Prelude.Maybe Prelude.Text)
metadata_name :: (Maybe Text -> f (Maybe Text)) -> Metadata -> f Metadata
metadata_name = (Metadata -> Maybe Text)
-> (Metadata -> Maybe Text -> Metadata)
-> Lens Metadata Metadata (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Metadata' {Maybe Text
name :: Maybe Text
$sel:name:Metadata' :: Metadata -> Maybe Text
name} -> Maybe Text
name) (\s :: Metadata
s@Metadata' {} Maybe Text
a -> Metadata
s {$sel:name:Metadata' :: Maybe Text
name = Maybe Text
a} :: Metadata)

instance Core.FromJSON Metadata where
  parseJSON :: Value -> Parser Metadata
parseJSON =
    String -> (Object -> Parser Metadata) -> Value -> Parser Metadata
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Metadata"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Metadata
Metadata'
            (Maybe Text -> Maybe Text -> Metadata)
-> Parser (Maybe Text) -> Parser (Maybe Text -> Metadata)
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
"Value") Parser (Maybe Text -> Metadata)
-> Parser (Maybe Text) -> Parser Metadata
forall (f :: * -> *) a b. Applicative f => 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
"Name")
      )

instance Prelude.Hashable Metadata

instance Prelude.NFData Metadata

instance Core.ToJSON Metadata where
  toJSON :: Metadata -> Value
toJSON Metadata' {Maybe Text
name :: Maybe Text
value :: Maybe Text
$sel:name:Metadata' :: Metadata -> Maybe Text
$sel:value:Metadata' :: Metadata -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Value" 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
value,
            (Text
"Name" 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
name
          ]
      )