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

-- | Describes key\/value pairs.
--
-- /See:/ 'newMetadata' smart constructor.
data Metadata = Metadata'
  { -- | The key name.
    Metadata -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The value.
    Metadata -> Maybe Text
value :: Prelude.Maybe Prelude.Text
  }
  deriving (Metadata -> Metadata -> Bool
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]
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
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. 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:
--
-- 'name', 'metadata_name' - The key name.
--
-- 'value', 'metadata_value' - The value.
newMetadata ::
  Metadata
newMetadata :: Metadata
newMetadata =
  Metadata'
    { $sel:name:Metadata' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:value:Metadata' :: Maybe Text
value = forall a. Maybe a
Prelude.Nothing
    }

-- | The key name.
metadata_name :: Lens.Lens' Metadata (Prelude.Maybe Prelude.Text)
metadata_name :: Lens' Metadata (Maybe Text)
metadata_name = 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)

-- | The value.
metadata_value :: Lens.Lens' Metadata (Prelude.Maybe Prelude.Text)
metadata_value :: Lens' Metadata (Maybe Text)
metadata_value = 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)

instance Data.FromJSON Metadata where
  parseJSON :: Value -> Parser Metadata
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Metadata"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> Metadata
Metadata'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Value")
      )

instance Prelude.Hashable Metadata where
  hashWithSalt :: Int -> Metadata -> Int
hashWithSalt Int
_salt Metadata' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:Metadata' :: Metadata -> Maybe Text
$sel:name:Metadata' :: Metadata -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
value

instance Prelude.NFData Metadata where
  rnf :: Metadata -> ()
rnf Metadata' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:Metadata' :: Metadata -> Maybe Text
$sel:name:Metadata' :: Metadata -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
value

instance Data.ToJSON Metadata where
  toJSON :: Metadata -> Value
toJSON Metadata' {Maybe Text
value :: Maybe Text
name :: Maybe Text
$sel:value:Metadata' :: Metadata -> Maybe Text
$sel:name:Metadata' :: Metadata -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Key
"Value" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
value
          ]
      )