{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

-- |
-- Module      : Amazonka.EC2.Internal
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka.com>
-- Stability   : experimental
-- Portability : non-portable (GHC extensions)
module Amazonka.EC2.Internal where

import Amazonka.Core.Lens.Internal
import Amazonka.Data
import Amazonka.Prelude

-- | Custom 'Tag' type which has an optional value component.
--
-- /See:/ 'tag' smart constructor.
data DeleteTag = DeleteTag'
  { -- | Tag keys are case-sensitive and accept a maximum of 127
    -- Unicode characters. May not begin with 'aws:'
    DeleteTag -> Text
key :: !Text,
    -- | Tag values are case-sensitive and accept a maximum of 255
    -- Unicode characters.
    DeleteTag -> Maybe Text
value :: !(Maybe Text)
  }
  deriving (DeleteTag -> DeleteTag -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DeleteTag -> DeleteTag -> Bool
$c/= :: DeleteTag -> DeleteTag -> Bool
== :: DeleteTag -> DeleteTag -> Bool
$c== :: DeleteTag -> DeleteTag -> Bool
Eq, ReadPrec [DeleteTag]
ReadPrec DeleteTag
Int -> ReadS DeleteTag
ReadS [DeleteTag]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DeleteTag]
$creadListPrec :: ReadPrec [DeleteTag]
readPrec :: ReadPrec DeleteTag
$creadPrec :: ReadPrec DeleteTag
readList :: ReadS [DeleteTag]
$creadList :: ReadS [DeleteTag]
readsPrec :: Int -> ReadS DeleteTag
$creadsPrec :: Int -> ReadS DeleteTag
Read, Int -> DeleteTag -> ShowS
[DeleteTag] -> ShowS
DeleteTag -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DeleteTag] -> ShowS
$cshowList :: [DeleteTag] -> ShowS
show :: DeleteTag -> String
$cshow :: DeleteTag -> String
showsPrec :: Int -> DeleteTag -> ShowS
$cshowsPrec :: Int -> DeleteTag -> ShowS
Show, forall x. Rep DeleteTag x -> DeleteTag
forall x. DeleteTag -> Rep DeleteTag x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DeleteTag x -> DeleteTag
$cfrom :: forall x. DeleteTag -> Rep DeleteTag x
Generic)

newDeleteTag ::
  -- | 'key'
  Text ->
  DeleteTag
newDeleteTag :: Text -> DeleteTag
newDeleteTag Text
key = DeleteTag' {Text
key :: Text
key :: Text
key, value :: Maybe Text
value = forall a. Maybe a
Nothing}

{-# INLINE deleteTag_key #-}
deleteTag_key :: Lens' DeleteTag Text
deleteTag_key :: Lens' DeleteTag Text
deleteTag_key = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens DeleteTag -> Text
key (\DeleteTag
s Text
a -> DeleteTag
s {key :: Text
key = Text
a})

{-# INLINE deleteTag_value #-}
deleteTag_value :: Lens' DeleteTag (Maybe Text)
deleteTag_value :: Lens' DeleteTag (Maybe Text)
deleteTag_value = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens DeleteTag -> Maybe Text
value (\DeleteTag
s Maybe Text
a -> DeleteTag
s {value :: Maybe Text
value = Maybe Text
a})

instance FromXML DeleteTag where
  parseXML :: [Node] -> Either String DeleteTag
parseXML [Node]
x = Text -> Maybe Text -> DeleteTag
DeleteTag' forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String a
.@ Text
"key") forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ([Node]
x forall a. FromXML a => [Node] -> Text -> Either String (Maybe a)
.@? Text
"value")

instance ToQuery DeleteTag where
  toQuery :: DeleteTag -> QueryString
toQuery DeleteTag' {Maybe Text
Text
value :: Maybe Text
key :: Text
value :: DeleteTag -> Maybe Text
key :: DeleteTag -> Text
..} =
    forall a. Monoid a => [a] -> a
mconcat
      [ ByteString
"Key" forall a. ToQuery a => ByteString -> a -> QueryString
=: Text
key,
        ByteString
"Value" forall a. ToQuery a => ByteString -> a -> QueryString
=: Maybe Text
value
      ]