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

import Amazonka.Chime.Types.SipRuleTargetApplication
import Amazonka.Chime.Types.SipRuleTriggerType
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

-- | The SIP rule details, including name, triggers, and target applications.
-- An AWS account can have multiple SIP rules.
--
-- /See:/ 'newSipRule' smart constructor.
data SipRule = SipRule'
  { -- | The time at which the SIP rule was created, in ISO 8601 format.
    SipRule -> Maybe ISO8601
createdTimestamp :: Prelude.Maybe Data.ISO8601,
    -- | Indicates whether the SIP rule is enabled or disabled. You must disable
    -- a rule before you can delete it.
    SipRule -> Maybe Bool
disabled :: Prelude.Maybe Prelude.Bool,
    -- | The name of the SIP rule.
    SipRule -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The SIP rule ID.
    SipRule -> Maybe Text
sipRuleId :: Prelude.Maybe Prelude.Text,
    -- | Target SIP media application and other details, such as priority and AWS
    -- Region, to be specified in the SIP rule. Only one SIP rule per AWS
    -- Region can be provided.
    SipRule -> Maybe (NonEmpty SipRuleTargetApplication)
targetApplications :: Prelude.Maybe (Prelude.NonEmpty SipRuleTargetApplication),
    -- | The type of trigger assigned to the SIP rule in @TriggerValue@,
    -- currently @RequestUriHostname@ or @ToPhoneNumber@.
    SipRule -> Maybe SipRuleTriggerType
triggerType :: Prelude.Maybe SipRuleTriggerType,
    -- | If @TriggerType@ is @RequestUriHostname@, then the value can be the
    -- outbound host name of the Amazon Chime Voice Connector. If @TriggerType@
    -- is @ToPhoneNumber@, then the value can be a customer-owned phone number
    -- in E164 format. @SipRule@ is triggered when a SIP rule requests host
    -- name or @ToPhoneNumber@ matches in the incoming SIP request.
    SipRule -> Maybe Text
triggerValue :: Prelude.Maybe Prelude.Text,
    -- | The time at which the SIP rule was last updated, in ISO 8601 format.
    SipRule -> Maybe ISO8601
updatedTimestamp :: Prelude.Maybe Data.ISO8601
  }
  deriving (SipRule -> SipRule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SipRule -> SipRule -> Bool
$c/= :: SipRule -> SipRule -> Bool
== :: SipRule -> SipRule -> Bool
$c== :: SipRule -> SipRule -> Bool
Prelude.Eq, ReadPrec [SipRule]
ReadPrec SipRule
Int -> ReadS SipRule
ReadS [SipRule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SipRule]
$creadListPrec :: ReadPrec [SipRule]
readPrec :: ReadPrec SipRule
$creadPrec :: ReadPrec SipRule
readList :: ReadS [SipRule]
$creadList :: ReadS [SipRule]
readsPrec :: Int -> ReadS SipRule
$creadsPrec :: Int -> ReadS SipRule
Prelude.Read, Int -> SipRule -> ShowS
[SipRule] -> ShowS
SipRule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SipRule] -> ShowS
$cshowList :: [SipRule] -> ShowS
show :: SipRule -> String
$cshow :: SipRule -> String
showsPrec :: Int -> SipRule -> ShowS
$cshowsPrec :: Int -> SipRule -> ShowS
Prelude.Show, forall x. Rep SipRule x -> SipRule
forall x. SipRule -> Rep SipRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SipRule x -> SipRule
$cfrom :: forall x. SipRule -> Rep SipRule x
Prelude.Generic)

-- |
-- Create a value of 'SipRule' 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:
--
-- 'createdTimestamp', 'sipRule_createdTimestamp' - The time at which the SIP rule was created, in ISO 8601 format.
--
-- 'disabled', 'sipRule_disabled' - Indicates whether the SIP rule is enabled or disabled. You must disable
-- a rule before you can delete it.
--
-- 'name', 'sipRule_name' - The name of the SIP rule.
--
-- 'sipRuleId', 'sipRule_sipRuleId' - The SIP rule ID.
--
-- 'targetApplications', 'sipRule_targetApplications' - Target SIP media application and other details, such as priority and AWS
-- Region, to be specified in the SIP rule. Only one SIP rule per AWS
-- Region can be provided.
--
-- 'triggerType', 'sipRule_triggerType' - The type of trigger assigned to the SIP rule in @TriggerValue@,
-- currently @RequestUriHostname@ or @ToPhoneNumber@.
--
-- 'triggerValue', 'sipRule_triggerValue' - If @TriggerType@ is @RequestUriHostname@, then the value can be the
-- outbound host name of the Amazon Chime Voice Connector. If @TriggerType@
-- is @ToPhoneNumber@, then the value can be a customer-owned phone number
-- in E164 format. @SipRule@ is triggered when a SIP rule requests host
-- name or @ToPhoneNumber@ matches in the incoming SIP request.
--
-- 'updatedTimestamp', 'sipRule_updatedTimestamp' - The time at which the SIP rule was last updated, in ISO 8601 format.
newSipRule ::
  SipRule
newSipRule :: SipRule
newSipRule =
  SipRule'
    { $sel:createdTimestamp:SipRule' :: Maybe ISO8601
createdTimestamp = forall a. Maybe a
Prelude.Nothing,
      $sel:disabled:SipRule' :: Maybe Bool
disabled = forall a. Maybe a
Prelude.Nothing,
      $sel:name:SipRule' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:sipRuleId:SipRule' :: Maybe Text
sipRuleId = forall a. Maybe a
Prelude.Nothing,
      $sel:targetApplications:SipRule' :: Maybe (NonEmpty SipRuleTargetApplication)
targetApplications = forall a. Maybe a
Prelude.Nothing,
      $sel:triggerType:SipRule' :: Maybe SipRuleTriggerType
triggerType = forall a. Maybe a
Prelude.Nothing,
      $sel:triggerValue:SipRule' :: Maybe Text
triggerValue = forall a. Maybe a
Prelude.Nothing,
      $sel:updatedTimestamp:SipRule' :: Maybe ISO8601
updatedTimestamp = forall a. Maybe a
Prelude.Nothing
    }

-- | The time at which the SIP rule was created, in ISO 8601 format.
sipRule_createdTimestamp :: Lens.Lens' SipRule (Prelude.Maybe Prelude.UTCTime)
sipRule_createdTimestamp :: Lens' SipRule (Maybe UTCTime)
sipRule_createdTimestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe ISO8601
createdTimestamp :: Maybe ISO8601
$sel:createdTimestamp:SipRule' :: SipRule -> Maybe ISO8601
createdTimestamp} -> Maybe ISO8601
createdTimestamp) (\s :: SipRule
s@SipRule' {} Maybe ISO8601
a -> SipRule
s {$sel:createdTimestamp:SipRule' :: Maybe ISO8601
createdTimestamp = Maybe ISO8601
a} :: SipRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | Indicates whether the SIP rule is enabled or disabled. You must disable
-- a rule before you can delete it.
sipRule_disabled :: Lens.Lens' SipRule (Prelude.Maybe Prelude.Bool)
sipRule_disabled :: Lens' SipRule (Maybe Bool)
sipRule_disabled = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe Bool
disabled :: Maybe Bool
$sel:disabled:SipRule' :: SipRule -> Maybe Bool
disabled} -> Maybe Bool
disabled) (\s :: SipRule
s@SipRule' {} Maybe Bool
a -> SipRule
s {$sel:disabled:SipRule' :: Maybe Bool
disabled = Maybe Bool
a} :: SipRule)

-- | The name of the SIP rule.
sipRule_name :: Lens.Lens' SipRule (Prelude.Maybe Prelude.Text)
sipRule_name :: Lens' SipRule (Maybe Text)
sipRule_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe Text
name :: Maybe Text
$sel:name:SipRule' :: SipRule -> Maybe Text
name} -> Maybe Text
name) (\s :: SipRule
s@SipRule' {} Maybe Text
a -> SipRule
s {$sel:name:SipRule' :: Maybe Text
name = Maybe Text
a} :: SipRule)

-- | The SIP rule ID.
sipRule_sipRuleId :: Lens.Lens' SipRule (Prelude.Maybe Prelude.Text)
sipRule_sipRuleId :: Lens' SipRule (Maybe Text)
sipRule_sipRuleId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe Text
sipRuleId :: Maybe Text
$sel:sipRuleId:SipRule' :: SipRule -> Maybe Text
sipRuleId} -> Maybe Text
sipRuleId) (\s :: SipRule
s@SipRule' {} Maybe Text
a -> SipRule
s {$sel:sipRuleId:SipRule' :: Maybe Text
sipRuleId = Maybe Text
a} :: SipRule)

-- | Target SIP media application and other details, such as priority and AWS
-- Region, to be specified in the SIP rule. Only one SIP rule per AWS
-- Region can be provided.
sipRule_targetApplications :: Lens.Lens' SipRule (Prelude.Maybe (Prelude.NonEmpty SipRuleTargetApplication))
sipRule_targetApplications :: Lens' SipRule (Maybe (NonEmpty SipRuleTargetApplication))
sipRule_targetApplications = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe (NonEmpty SipRuleTargetApplication)
targetApplications :: Maybe (NonEmpty SipRuleTargetApplication)
$sel:targetApplications:SipRule' :: SipRule -> Maybe (NonEmpty SipRuleTargetApplication)
targetApplications} -> Maybe (NonEmpty SipRuleTargetApplication)
targetApplications) (\s :: SipRule
s@SipRule' {} Maybe (NonEmpty SipRuleTargetApplication)
a -> SipRule
s {$sel:targetApplications:SipRule' :: Maybe (NonEmpty SipRuleTargetApplication)
targetApplications = Maybe (NonEmpty SipRuleTargetApplication)
a} :: SipRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The type of trigger assigned to the SIP rule in @TriggerValue@,
-- currently @RequestUriHostname@ or @ToPhoneNumber@.
sipRule_triggerType :: Lens.Lens' SipRule (Prelude.Maybe SipRuleTriggerType)
sipRule_triggerType :: Lens' SipRule (Maybe SipRuleTriggerType)
sipRule_triggerType = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe SipRuleTriggerType
triggerType :: Maybe SipRuleTriggerType
$sel:triggerType:SipRule' :: SipRule -> Maybe SipRuleTriggerType
triggerType} -> Maybe SipRuleTriggerType
triggerType) (\s :: SipRule
s@SipRule' {} Maybe SipRuleTriggerType
a -> SipRule
s {$sel:triggerType:SipRule' :: Maybe SipRuleTriggerType
triggerType = Maybe SipRuleTriggerType
a} :: SipRule)

-- | If @TriggerType@ is @RequestUriHostname@, then the value can be the
-- outbound host name of the Amazon Chime Voice Connector. If @TriggerType@
-- is @ToPhoneNumber@, then the value can be a customer-owned phone number
-- in E164 format. @SipRule@ is triggered when a SIP rule requests host
-- name or @ToPhoneNumber@ matches in the incoming SIP request.
sipRule_triggerValue :: Lens.Lens' SipRule (Prelude.Maybe Prelude.Text)
sipRule_triggerValue :: Lens' SipRule (Maybe Text)
sipRule_triggerValue = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe Text
triggerValue :: Maybe Text
$sel:triggerValue:SipRule' :: SipRule -> Maybe Text
triggerValue} -> Maybe Text
triggerValue) (\s :: SipRule
s@SipRule' {} Maybe Text
a -> SipRule
s {$sel:triggerValue:SipRule' :: Maybe Text
triggerValue = Maybe Text
a} :: SipRule)

-- | The time at which the SIP rule was last updated, in ISO 8601 format.
sipRule_updatedTimestamp :: Lens.Lens' SipRule (Prelude.Maybe Prelude.UTCTime)
sipRule_updatedTimestamp :: Lens' SipRule (Maybe UTCTime)
sipRule_updatedTimestamp = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\SipRule' {Maybe ISO8601
updatedTimestamp :: Maybe ISO8601
$sel:updatedTimestamp:SipRule' :: SipRule -> Maybe ISO8601
updatedTimestamp} -> Maybe ISO8601
updatedTimestamp) (\s :: SipRule
s@SipRule' {} Maybe ISO8601
a -> SipRule
s {$sel:updatedTimestamp:SipRule' :: Maybe ISO8601
updatedTimestamp = Maybe ISO8601
a} :: SipRule) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

instance Data.FromJSON SipRule where
  parseJSON :: Value -> Parser SipRule
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"SipRule"
      ( \Object
x ->
          Maybe ISO8601
-> Maybe Bool
-> Maybe Text
-> Maybe Text
-> Maybe (NonEmpty SipRuleTargetApplication)
-> Maybe SipRuleTriggerType
-> Maybe Text
-> Maybe ISO8601
-> SipRule
SipRule'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CreatedTimestamp")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Disabled")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Name")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"SipRuleId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"TargetApplications")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"TriggerType")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"TriggerValue")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"UpdatedTimestamp")
      )

instance Prelude.Hashable SipRule where
  hashWithSalt :: Int -> SipRule -> Int
hashWithSalt Int
_salt SipRule' {Maybe Bool
Maybe (NonEmpty SipRuleTargetApplication)
Maybe Text
Maybe ISO8601
Maybe SipRuleTriggerType
updatedTimestamp :: Maybe ISO8601
triggerValue :: Maybe Text
triggerType :: Maybe SipRuleTriggerType
targetApplications :: Maybe (NonEmpty SipRuleTargetApplication)
sipRuleId :: Maybe Text
name :: Maybe Text
disabled :: Maybe Bool
createdTimestamp :: Maybe ISO8601
$sel:updatedTimestamp:SipRule' :: SipRule -> Maybe ISO8601
$sel:triggerValue:SipRule' :: SipRule -> Maybe Text
$sel:triggerType:SipRule' :: SipRule -> Maybe SipRuleTriggerType
$sel:targetApplications:SipRule' :: SipRule -> Maybe (NonEmpty SipRuleTargetApplication)
$sel:sipRuleId:SipRule' :: SipRule -> Maybe Text
$sel:name:SipRule' :: SipRule -> Maybe Text
$sel:disabled:SipRule' :: SipRule -> Maybe Bool
$sel:createdTimestamp:SipRule' :: SipRule -> Maybe ISO8601
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ISO8601
createdTimestamp
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Bool
disabled
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
sipRuleId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty SipRuleTargetApplication)
targetApplications
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe SipRuleTriggerType
triggerType
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
triggerValue
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ISO8601
updatedTimestamp

instance Prelude.NFData SipRule where
  rnf :: SipRule -> ()
rnf SipRule' {Maybe Bool
Maybe (NonEmpty SipRuleTargetApplication)
Maybe Text
Maybe ISO8601
Maybe SipRuleTriggerType
updatedTimestamp :: Maybe ISO8601
triggerValue :: Maybe Text
triggerType :: Maybe SipRuleTriggerType
targetApplications :: Maybe (NonEmpty SipRuleTargetApplication)
sipRuleId :: Maybe Text
name :: Maybe Text
disabled :: Maybe Bool
createdTimestamp :: Maybe ISO8601
$sel:updatedTimestamp:SipRule' :: SipRule -> Maybe ISO8601
$sel:triggerValue:SipRule' :: SipRule -> Maybe Text
$sel:triggerType:SipRule' :: SipRule -> Maybe SipRuleTriggerType
$sel:targetApplications:SipRule' :: SipRule -> Maybe (NonEmpty SipRuleTargetApplication)
$sel:sipRuleId:SipRule' :: SipRule -> Maybe Text
$sel:name:SipRule' :: SipRule -> Maybe Text
$sel:disabled:SipRule' :: SipRule -> Maybe Bool
$sel:createdTimestamp:SipRule' :: SipRule -> Maybe ISO8601
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe ISO8601
createdTimestamp
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Bool
disabled
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
sipRuleId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty SipRuleTargetApplication)
targetApplications
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe SipRuleTriggerType
triggerType
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
triggerValue
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ISO8601
updatedTimestamp