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

-- | 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
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]
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
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. 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'
    { $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 :: Lens' App Text
app_appName = 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 :: Lens' App Text
app_protocol = 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 :: Lens' App Natural
app_port = 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 Data.FromJSON App where
  parseJSON :: Value -> Parser App
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"App"
      ( \Object
x ->
          Text -> Text -> Natural -> App
App'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"AppName")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Protocol")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Port")
      )

instance Prelude.Hashable App where
  hashWithSalt :: Int -> App -> Int
hashWithSalt Int
_salt App' {Natural
Text
port :: Natural
protocol :: Text
appName :: Text
$sel:port:App' :: App -> Natural
$sel:protocol:App' :: App -> Text
$sel:appName:App' :: App -> Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
appName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
protocol
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Natural
port

instance Prelude.NFData App where
  rnf :: App -> ()
rnf App' {Natural
Text
port :: Natural
protocol :: Text
appName :: Text
$sel:port:App' :: App -> Natural
$sel:protocol:App' :: App -> Text
$sel:appName:App' :: App -> Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Text
appName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
protocol
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Natural
port

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ forall a. a -> Maybe a
Prelude.Just (Key
"AppName" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
appName),
            forall a. a -> Maybe a
Prelude.Just (Key
"Protocol" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
protocol),
            forall a. a -> Maybe a
Prelude.Just (Key
"Port" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Natural
port)
          ]
      )