{-# 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.FMS.Types.App
-- 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.FMS.Types.App where

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

-- | An individual Firewall Manager application.
--
-- /See:/ 'newApp' smart constructor.
data App = App'
  { -- | The application\'s name.
    App -> Text
appName :: Prelude.Text,
    -- | The IP protocol name or number. The name can be one of @tcp@, @udp@, or
    -- @icmp@. For information on possible numbers, see
    -- <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml Protocol Numbers>.
    App -> Text
protocol :: Prelude.Text,
    -- | The application\'s port number, for example @80@.
    App -> Natural
port :: Prelude.Natural
  }
  deriving (App -> App -> Bool
(App -> App -> Bool) -> (App -> App -> Bool) -> Eq App
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: App -> App -> Bool
$c/= :: App -> App -> Bool
== :: App -> App -> Bool
$c== :: App -> App -> Bool
Prelude.Eq, ReadPrec [App]
ReadPrec App
Int -> ReadS App
ReadS [App]
(Int -> ReadS App)
-> ReadS [App] -> ReadPrec App -> ReadPrec [App] -> Read App
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [App]
$creadListPrec :: ReadPrec [App]
readPrec :: ReadPrec App
$creadPrec :: ReadPrec App
readList :: ReadS [App]
$creadList :: ReadS [App]
readsPrec :: Int -> ReadS App
$creadsPrec :: Int -> ReadS App
Prelude.Read, Int -> App -> ShowS
[App] -> ShowS
App -> String
(Int -> App -> ShowS)
-> (App -> String) -> ([App] -> ShowS) -> Show App
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [App] -> ShowS
$cshowList :: [App] -> ShowS
show :: App -> String
$cshow :: App -> String
showsPrec :: Int -> App -> ShowS
$cshowsPrec :: Int -> App -> ShowS
Prelude.Show, (forall x. App -> Rep App x)
-> (forall x. Rep App x -> App) -> Generic App
forall x. Rep App x -> App
forall x. App -> Rep App x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep App x -> App
$cfrom :: forall x. App -> Rep App x
Prelude.Generic)

-- |
-- Create a value of 'App' 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:
--
-- 'appName', 'app_appName' - The application\'s name.
--
-- 'protocol', 'app_protocol' - The IP protocol name or number. The name can be one of @tcp@, @udp@, or
-- @icmp@. For information on possible numbers, see
-- <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml Protocol Numbers>.
--
-- 'port', 'app_port' - The application\'s port number, for example @80@.
newApp ::
  -- | 'appName'
  Prelude.Text ->
  -- | 'protocol'
  Prelude.Text ->
  -- | 'port'
  Prelude.Natural ->
  App
newApp :: Text -> Text -> Natural -> App
newApp Text
pAppName_ Text
pProtocol_ Natural
pPort_ =
  App' :: Text -> Text -> Natural -> App
App'
    { $sel:appName:App' :: Text
appName = Text
pAppName_,
      $sel:protocol:App' :: Text
protocol = Text
pProtocol_,
      $sel:port:App' :: Natural
port = Natural
pPort_
    }

-- | The application\'s name.
app_appName :: Lens.Lens' App Prelude.Text
app_appName :: (Text -> f Text) -> App -> f App
app_appName = (App -> Text) -> (App -> Text -> App) -> Lens App App Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\App' {Text
appName :: Text
$sel:appName:App' :: App -> Text
appName} -> Text
appName) (\s :: App
s@App' {} Text
a -> App
s {$sel:appName:App' :: Text
appName = Text
a} :: App)

-- | The IP protocol name or number. The name can be one of @tcp@, @udp@, or
-- @icmp@. For information on possible numbers, see
-- <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml Protocol Numbers>.
app_protocol :: Lens.Lens' App Prelude.Text
app_protocol :: (Text -> f Text) -> App -> f App
app_protocol = (App -> Text) -> (App -> Text -> App) -> Lens App App Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\App' {Text
protocol :: Text
$sel:protocol:App' :: App -> Text
protocol} -> Text
protocol) (\s :: App
s@App' {} Text
a -> App
s {$sel:protocol:App' :: Text
protocol = Text
a} :: App)

-- | The application\'s port number, for example @80@.
app_port :: Lens.Lens' App Prelude.Natural
app_port :: (Natural -> f Natural) -> App -> f App
app_port = (App -> Natural)
-> (App -> Natural -> App) -> Lens App App Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\App' {Natural
port :: Natural
$sel:port:App' :: App -> Natural
port} -> Natural
port) (\s :: App
s@App' {} Natural
a -> App
s {$sel:port:App' :: Natural
port = Natural
a} :: App)

instance Core.FromJSON App where
  parseJSON :: Value -> Parser App
parseJSON =
    String -> (Object -> Parser App) -> Value -> Parser App
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"App"
      ( \Object
x ->
          Text -> Text -> Natural -> App
App'
            (Text -> Text -> Natural -> App)
-> Parser Text -> Parser (Text -> Natural -> App)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"AppName")
            Parser (Text -> Natural -> App)
-> Parser Text -> Parser (Natural -> App)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Protocol")
            Parser (Natural -> App) -> Parser Natural -> Parser App
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Port")
      )

instance Prelude.Hashable App

instance Prelude.NFData App

instance Core.ToJSON App where
  toJSON :: App -> Value
toJSON App' {Natural
Text
port :: Natural
protocol :: Text
appName :: Text
$sel:port:App' :: App -> Natural
$sel:protocol:App' :: App -> Text
$sel:appName:App' :: App -> 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
"AppName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
appName),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Protocol" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
protocol),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Port" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
port)
          ]
      )