{-# 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.Chime.Types.OriginationRoute
-- 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.Chime.Types.OriginationRoute where

import Amazonka.Chime.Types.OriginationRouteProtocol
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Origination routes define call distribution properties for your SIP
-- hosts to receive inbound calls using your Amazon Chime Voice Connector.
-- Limit: Ten origination routes for each Amazon Chime Voice Connector.
--
-- The parameters listed below are not required, but you must use at least
-- one.
--
-- /See:/ 'newOriginationRoute' smart constructor.
data OriginationRoute = OriginationRoute'
  { -- | The priority associated with the host, with 1 being the highest
    -- priority. Higher priority hosts are attempted first.
    OriginationRoute -> Maybe Natural
priority :: Prelude.Maybe Prelude.Natural,
    -- | The weight associated with the host. If hosts are equal in priority,
    -- calls are redistributed among them based on their relative weight.
    OriginationRoute -> Maybe Natural
weight :: Prelude.Maybe Prelude.Natural,
    -- | The protocol to use for the origination route. Encryption-enabled Amazon
    -- Chime Voice Connectors use TCP protocol by default.
    OriginationRoute -> Maybe OriginationRouteProtocol
protocol :: Prelude.Maybe OriginationRouteProtocol,
    -- | The FQDN or IP address to contact for origination traffic.
    OriginationRoute -> Maybe Text
host :: Prelude.Maybe Prelude.Text,
    -- | The designated origination route port. Defaults to 5060.
    OriginationRoute -> Maybe Natural
port :: Prelude.Maybe Prelude.Natural
  }
  deriving (OriginationRoute -> OriginationRoute -> Bool
(OriginationRoute -> OriginationRoute -> Bool)
-> (OriginationRoute -> OriginationRoute -> Bool)
-> Eq OriginationRoute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OriginationRoute -> OriginationRoute -> Bool
$c/= :: OriginationRoute -> OriginationRoute -> Bool
== :: OriginationRoute -> OriginationRoute -> Bool
$c== :: OriginationRoute -> OriginationRoute -> Bool
Prelude.Eq, ReadPrec [OriginationRoute]
ReadPrec OriginationRoute
Int -> ReadS OriginationRoute
ReadS [OriginationRoute]
(Int -> ReadS OriginationRoute)
-> ReadS [OriginationRoute]
-> ReadPrec OriginationRoute
-> ReadPrec [OriginationRoute]
-> Read OriginationRoute
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OriginationRoute]
$creadListPrec :: ReadPrec [OriginationRoute]
readPrec :: ReadPrec OriginationRoute
$creadPrec :: ReadPrec OriginationRoute
readList :: ReadS [OriginationRoute]
$creadList :: ReadS [OriginationRoute]
readsPrec :: Int -> ReadS OriginationRoute
$creadsPrec :: Int -> ReadS OriginationRoute
Prelude.Read, Int -> OriginationRoute -> ShowS
[OriginationRoute] -> ShowS
OriginationRoute -> String
(Int -> OriginationRoute -> ShowS)
-> (OriginationRoute -> String)
-> ([OriginationRoute] -> ShowS)
-> Show OriginationRoute
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OriginationRoute] -> ShowS
$cshowList :: [OriginationRoute] -> ShowS
show :: OriginationRoute -> String
$cshow :: OriginationRoute -> String
showsPrec :: Int -> OriginationRoute -> ShowS
$cshowsPrec :: Int -> OriginationRoute -> ShowS
Prelude.Show, (forall x. OriginationRoute -> Rep OriginationRoute x)
-> (forall x. Rep OriginationRoute x -> OriginationRoute)
-> Generic OriginationRoute
forall x. Rep OriginationRoute x -> OriginationRoute
forall x. OriginationRoute -> Rep OriginationRoute x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OriginationRoute x -> OriginationRoute
$cfrom :: forall x. OriginationRoute -> Rep OriginationRoute x
Prelude.Generic)

-- |
-- Create a value of 'OriginationRoute' 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:
--
-- 'priority', 'originationRoute_priority' - The priority associated with the host, with 1 being the highest
-- priority. Higher priority hosts are attempted first.
--
-- 'weight', 'originationRoute_weight' - The weight associated with the host. If hosts are equal in priority,
-- calls are redistributed among them based on their relative weight.
--
-- 'protocol', 'originationRoute_protocol' - The protocol to use for the origination route. Encryption-enabled Amazon
-- Chime Voice Connectors use TCP protocol by default.
--
-- 'host', 'originationRoute_host' - The FQDN or IP address to contact for origination traffic.
--
-- 'port', 'originationRoute_port' - The designated origination route port. Defaults to 5060.
newOriginationRoute ::
  OriginationRoute
newOriginationRoute :: OriginationRoute
newOriginationRoute =
  OriginationRoute' :: Maybe Natural
-> Maybe Natural
-> Maybe OriginationRouteProtocol
-> Maybe Text
-> Maybe Natural
-> OriginationRoute
OriginationRoute'
    { $sel:priority:OriginationRoute' :: Maybe Natural
priority = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:weight:OriginationRoute' :: Maybe Natural
weight = Maybe Natural
forall a. Maybe a
Prelude.Nothing,
      $sel:protocol:OriginationRoute' :: Maybe OriginationRouteProtocol
protocol = Maybe OriginationRouteProtocol
forall a. Maybe a
Prelude.Nothing,
      $sel:host:OriginationRoute' :: Maybe Text
host = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:port:OriginationRoute' :: Maybe Natural
port = Maybe Natural
forall a. Maybe a
Prelude.Nothing
    }

-- | The priority associated with the host, with 1 being the highest
-- priority. Higher priority hosts are attempted first.
originationRoute_priority :: Lens.Lens' OriginationRoute (Prelude.Maybe Prelude.Natural)
originationRoute_priority :: (Maybe Natural -> f (Maybe Natural))
-> OriginationRoute -> f OriginationRoute
originationRoute_priority = (OriginationRoute -> Maybe Natural)
-> (OriginationRoute -> Maybe Natural -> OriginationRoute)
-> Lens
     OriginationRoute OriginationRoute (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginationRoute' {Maybe Natural
priority :: Maybe Natural
$sel:priority:OriginationRoute' :: OriginationRoute -> Maybe Natural
priority} -> Maybe Natural
priority) (\s :: OriginationRoute
s@OriginationRoute' {} Maybe Natural
a -> OriginationRoute
s {$sel:priority:OriginationRoute' :: Maybe Natural
priority = Maybe Natural
a} :: OriginationRoute)

-- | The weight associated with the host. If hosts are equal in priority,
-- calls are redistributed among them based on their relative weight.
originationRoute_weight :: Lens.Lens' OriginationRoute (Prelude.Maybe Prelude.Natural)
originationRoute_weight :: (Maybe Natural -> f (Maybe Natural))
-> OriginationRoute -> f OriginationRoute
originationRoute_weight = (OriginationRoute -> Maybe Natural)
-> (OriginationRoute -> Maybe Natural -> OriginationRoute)
-> Lens
     OriginationRoute OriginationRoute (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginationRoute' {Maybe Natural
weight :: Maybe Natural
$sel:weight:OriginationRoute' :: OriginationRoute -> Maybe Natural
weight} -> Maybe Natural
weight) (\s :: OriginationRoute
s@OriginationRoute' {} Maybe Natural
a -> OriginationRoute
s {$sel:weight:OriginationRoute' :: Maybe Natural
weight = Maybe Natural
a} :: OriginationRoute)

-- | The protocol to use for the origination route. Encryption-enabled Amazon
-- Chime Voice Connectors use TCP protocol by default.
originationRoute_protocol :: Lens.Lens' OriginationRoute (Prelude.Maybe OriginationRouteProtocol)
originationRoute_protocol :: (Maybe OriginationRouteProtocol
 -> f (Maybe OriginationRouteProtocol))
-> OriginationRoute -> f OriginationRoute
originationRoute_protocol = (OriginationRoute -> Maybe OriginationRouteProtocol)
-> (OriginationRoute
    -> Maybe OriginationRouteProtocol -> OriginationRoute)
-> Lens
     OriginationRoute
     OriginationRoute
     (Maybe OriginationRouteProtocol)
     (Maybe OriginationRouteProtocol)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginationRoute' {Maybe OriginationRouteProtocol
protocol :: Maybe OriginationRouteProtocol
$sel:protocol:OriginationRoute' :: OriginationRoute -> Maybe OriginationRouteProtocol
protocol} -> Maybe OriginationRouteProtocol
protocol) (\s :: OriginationRoute
s@OriginationRoute' {} Maybe OriginationRouteProtocol
a -> OriginationRoute
s {$sel:protocol:OriginationRoute' :: Maybe OriginationRouteProtocol
protocol = Maybe OriginationRouteProtocol
a} :: OriginationRoute)

-- | The FQDN or IP address to contact for origination traffic.
originationRoute_host :: Lens.Lens' OriginationRoute (Prelude.Maybe Prelude.Text)
originationRoute_host :: (Maybe Text -> f (Maybe Text))
-> OriginationRoute -> f OriginationRoute
originationRoute_host = (OriginationRoute -> Maybe Text)
-> (OriginationRoute -> Maybe Text -> OriginationRoute)
-> Lens OriginationRoute OriginationRoute (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginationRoute' {Maybe Text
host :: Maybe Text
$sel:host:OriginationRoute' :: OriginationRoute -> Maybe Text
host} -> Maybe Text
host) (\s :: OriginationRoute
s@OriginationRoute' {} Maybe Text
a -> OriginationRoute
s {$sel:host:OriginationRoute' :: Maybe Text
host = Maybe Text
a} :: OriginationRoute)

-- | The designated origination route port. Defaults to 5060.
originationRoute_port :: Lens.Lens' OriginationRoute (Prelude.Maybe Prelude.Natural)
originationRoute_port :: (Maybe Natural -> f (Maybe Natural))
-> OriginationRoute -> f OriginationRoute
originationRoute_port = (OriginationRoute -> Maybe Natural)
-> (OriginationRoute -> Maybe Natural -> OriginationRoute)
-> Lens
     OriginationRoute OriginationRoute (Maybe Natural) (Maybe Natural)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\OriginationRoute' {Maybe Natural
port :: Maybe Natural
$sel:port:OriginationRoute' :: OriginationRoute -> Maybe Natural
port} -> Maybe Natural
port) (\s :: OriginationRoute
s@OriginationRoute' {} Maybe Natural
a -> OriginationRoute
s {$sel:port:OriginationRoute' :: Maybe Natural
port = Maybe Natural
a} :: OriginationRoute)

instance Core.FromJSON OriginationRoute where
  parseJSON :: Value -> Parser OriginationRoute
parseJSON =
    String
-> (Object -> Parser OriginationRoute)
-> Value
-> Parser OriginationRoute
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"OriginationRoute"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe OriginationRouteProtocol
-> Maybe Text
-> Maybe Natural
-> OriginationRoute
OriginationRoute'
            (Maybe Natural
 -> Maybe Natural
 -> Maybe OriginationRouteProtocol
 -> Maybe Text
 -> Maybe Natural
 -> OriginationRoute)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe OriginationRouteProtocol
      -> Maybe Text
      -> Maybe Natural
      -> OriginationRoute)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Priority")
            Parser
  (Maybe Natural
   -> Maybe OriginationRouteProtocol
   -> Maybe Text
   -> Maybe Natural
   -> OriginationRoute)
-> Parser (Maybe Natural)
-> Parser
     (Maybe OriginationRouteProtocol
      -> Maybe Text -> Maybe Natural -> OriginationRoute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Weight")
            Parser
  (Maybe OriginationRouteProtocol
   -> Maybe Text -> Maybe Natural -> OriginationRoute)
-> Parser (Maybe OriginationRouteProtocol)
-> Parser (Maybe Text -> Maybe Natural -> OriginationRoute)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe OriginationRouteProtocol)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Protocol")
            Parser (Maybe Text -> Maybe Natural -> OriginationRoute)
-> Parser (Maybe Text)
-> Parser (Maybe Natural -> OriginationRoute)
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
"Host")
            Parser (Maybe Natural -> OriginationRoute)
-> Parser (Maybe Natural) -> Parser OriginationRoute
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Natural)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Port")
      )

instance Prelude.Hashable OriginationRoute

instance Prelude.NFData OriginationRoute

instance Core.ToJSON OriginationRoute where
  toJSON :: OriginationRoute -> Value
toJSON OriginationRoute' {Maybe Natural
Maybe Text
Maybe OriginationRouteProtocol
port :: Maybe Natural
host :: Maybe Text
protocol :: Maybe OriginationRouteProtocol
weight :: Maybe Natural
priority :: Maybe Natural
$sel:port:OriginationRoute' :: OriginationRoute -> Maybe Natural
$sel:host:OriginationRoute' :: OriginationRoute -> Maybe Text
$sel:protocol:OriginationRoute' :: OriginationRoute -> Maybe OriginationRouteProtocol
$sel:weight:OriginationRoute' :: OriginationRoute -> Maybe Natural
$sel:priority:OriginationRoute' :: OriginationRoute -> Maybe Natural
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Priority" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
priority,
            (Text
"Weight" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
weight,
            (Text
"Protocol" Text -> OriginationRouteProtocol -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (OriginationRouteProtocol -> Pair)
-> Maybe OriginationRouteProtocol -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe OriginationRouteProtocol
protocol,
            (Text
"Host" 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
host,
            (Text
"Port" Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Natural -> Pair) -> Maybe Natural -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
port
          ]
      )