{-# 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.WorkSpaces.Types.IpRuleItem
-- 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.WorkSpaces.Types.IpRuleItem where

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

-- | Describes a rule for an IP access control group.
--
-- /See:/ 'newIpRuleItem' smart constructor.
data IpRuleItem = IpRuleItem'
  { -- | The description.
    IpRuleItem -> Maybe Text
ruleDesc :: Prelude.Maybe Prelude.Text,
    -- | The IP address range, in CIDR notation.
    IpRuleItem -> Maybe Text
ipRule :: Prelude.Maybe Prelude.Text
  }
  deriving (IpRuleItem -> IpRuleItem -> Bool
(IpRuleItem -> IpRuleItem -> Bool)
-> (IpRuleItem -> IpRuleItem -> Bool) -> Eq IpRuleItem
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IpRuleItem -> IpRuleItem -> Bool
$c/= :: IpRuleItem -> IpRuleItem -> Bool
== :: IpRuleItem -> IpRuleItem -> Bool
$c== :: IpRuleItem -> IpRuleItem -> Bool
Prelude.Eq, ReadPrec [IpRuleItem]
ReadPrec IpRuleItem
Int -> ReadS IpRuleItem
ReadS [IpRuleItem]
(Int -> ReadS IpRuleItem)
-> ReadS [IpRuleItem]
-> ReadPrec IpRuleItem
-> ReadPrec [IpRuleItem]
-> Read IpRuleItem
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IpRuleItem]
$creadListPrec :: ReadPrec [IpRuleItem]
readPrec :: ReadPrec IpRuleItem
$creadPrec :: ReadPrec IpRuleItem
readList :: ReadS [IpRuleItem]
$creadList :: ReadS [IpRuleItem]
readsPrec :: Int -> ReadS IpRuleItem
$creadsPrec :: Int -> ReadS IpRuleItem
Prelude.Read, Int -> IpRuleItem -> ShowS
[IpRuleItem] -> ShowS
IpRuleItem -> String
(Int -> IpRuleItem -> ShowS)
-> (IpRuleItem -> String)
-> ([IpRuleItem] -> ShowS)
-> Show IpRuleItem
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IpRuleItem] -> ShowS
$cshowList :: [IpRuleItem] -> ShowS
show :: IpRuleItem -> String
$cshow :: IpRuleItem -> String
showsPrec :: Int -> IpRuleItem -> ShowS
$cshowsPrec :: Int -> IpRuleItem -> ShowS
Prelude.Show, (forall x. IpRuleItem -> Rep IpRuleItem x)
-> (forall x. Rep IpRuleItem x -> IpRuleItem) -> Generic IpRuleItem
forall x. Rep IpRuleItem x -> IpRuleItem
forall x. IpRuleItem -> Rep IpRuleItem x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep IpRuleItem x -> IpRuleItem
$cfrom :: forall x. IpRuleItem -> Rep IpRuleItem x
Prelude.Generic)

-- |
-- Create a value of 'IpRuleItem' 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:
--
-- 'ruleDesc', 'ipRuleItem_ruleDesc' - The description.
--
-- 'ipRule', 'ipRuleItem_ipRule' - The IP address range, in CIDR notation.
newIpRuleItem ::
  IpRuleItem
newIpRuleItem :: IpRuleItem
newIpRuleItem =
  IpRuleItem' :: Maybe Text -> Maybe Text -> IpRuleItem
IpRuleItem'
    { $sel:ruleDesc:IpRuleItem' :: Maybe Text
ruleDesc = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:ipRule:IpRuleItem' :: Maybe Text
ipRule = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

-- | The description.
ipRuleItem_ruleDesc :: Lens.Lens' IpRuleItem (Prelude.Maybe Prelude.Text)
ipRuleItem_ruleDesc :: (Maybe Text -> f (Maybe Text)) -> IpRuleItem -> f IpRuleItem
ipRuleItem_ruleDesc = (IpRuleItem -> Maybe Text)
-> (IpRuleItem -> Maybe Text -> IpRuleItem)
-> Lens IpRuleItem IpRuleItem (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IpRuleItem' {Maybe Text
ruleDesc :: Maybe Text
$sel:ruleDesc:IpRuleItem' :: IpRuleItem -> Maybe Text
ruleDesc} -> Maybe Text
ruleDesc) (\s :: IpRuleItem
s@IpRuleItem' {} Maybe Text
a -> IpRuleItem
s {$sel:ruleDesc:IpRuleItem' :: Maybe Text
ruleDesc = Maybe Text
a} :: IpRuleItem)

-- | The IP address range, in CIDR notation.
ipRuleItem_ipRule :: Lens.Lens' IpRuleItem (Prelude.Maybe Prelude.Text)
ipRuleItem_ipRule :: (Maybe Text -> f (Maybe Text)) -> IpRuleItem -> f IpRuleItem
ipRuleItem_ipRule = (IpRuleItem -> Maybe Text)
-> (IpRuleItem -> Maybe Text -> IpRuleItem)
-> Lens IpRuleItem IpRuleItem (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\IpRuleItem' {Maybe Text
ipRule :: Maybe Text
$sel:ipRule:IpRuleItem' :: IpRuleItem -> Maybe Text
ipRule} -> Maybe Text
ipRule) (\s :: IpRuleItem
s@IpRuleItem' {} Maybe Text
a -> IpRuleItem
s {$sel:ipRule:IpRuleItem' :: Maybe Text
ipRule = Maybe Text
a} :: IpRuleItem)

instance Core.FromJSON IpRuleItem where
  parseJSON :: Value -> Parser IpRuleItem
parseJSON =
    String
-> (Object -> Parser IpRuleItem) -> Value -> Parser IpRuleItem
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"IpRuleItem"
      ( \Object
x ->
          Maybe Text -> Maybe Text -> IpRuleItem
IpRuleItem'
            (Maybe Text -> Maybe Text -> IpRuleItem)
-> Parser (Maybe Text) -> Parser (Maybe Text -> IpRuleItem)
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
"ruleDesc")
            Parser (Maybe Text -> IpRuleItem)
-> Parser (Maybe Text) -> Parser IpRuleItem
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
"ipRule")
      )

instance Prelude.Hashable IpRuleItem

instance Prelude.NFData IpRuleItem

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