{-# 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.Lightsail.Types.Origin
-- 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.Lightsail.Types.Origin where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import Amazonka.Lightsail.Types.OriginProtocolPolicyEnum
import Amazonka.Lightsail.Types.RegionName
import Amazonka.Lightsail.Types.ResourceType
import qualified Amazonka.Prelude as Prelude

-- | Describes the origin resource of an Amazon Lightsail content delivery
-- network (CDN) distribution.
--
-- An origin can be a Lightsail instance or load balancer. A distribution
-- pulls content from an origin, caches it, and serves it to viewers via a
-- worldwide network of edge servers.
--
-- /See:/ 'newOrigin' smart constructor.
data Origin = Origin'
  { -- | The AWS Region name of the origin resource.
    Origin -> Maybe RegionName
regionName :: Prelude.Maybe RegionName,
    -- | The resource type of the origin resource (e.g., /Instance/).
    Origin -> Maybe ResourceType
resourceType :: Prelude.Maybe ResourceType,
    -- | The name of the origin resource.
    Origin -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | The protocol that your Amazon Lightsail distribution uses when
    -- establishing a connection with your origin to pull content.
    Origin -> Maybe OriginProtocolPolicyEnum
protocolPolicy :: Prelude.Maybe OriginProtocolPolicyEnum
  }
  deriving (Origin -> Origin -> Bool
(Origin -> Origin -> Bool)
-> (Origin -> Origin -> Bool) -> Eq Origin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Origin -> Origin -> Bool
$c/= :: Origin -> Origin -> Bool
== :: Origin -> Origin -> Bool
$c== :: Origin -> Origin -> Bool
Prelude.Eq, ReadPrec [Origin]
ReadPrec Origin
Int -> ReadS Origin
ReadS [Origin]
(Int -> ReadS Origin)
-> ReadS [Origin]
-> ReadPrec Origin
-> ReadPrec [Origin]
-> Read Origin
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Origin]
$creadListPrec :: ReadPrec [Origin]
readPrec :: ReadPrec Origin
$creadPrec :: ReadPrec Origin
readList :: ReadS [Origin]
$creadList :: ReadS [Origin]
readsPrec :: Int -> ReadS Origin
$creadsPrec :: Int -> ReadS Origin
Prelude.Read, Int -> Origin -> ShowS
[Origin] -> ShowS
Origin -> String
(Int -> Origin -> ShowS)
-> (Origin -> String) -> ([Origin] -> ShowS) -> Show Origin
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Origin] -> ShowS
$cshowList :: [Origin] -> ShowS
show :: Origin -> String
$cshow :: Origin -> String
showsPrec :: Int -> Origin -> ShowS
$cshowsPrec :: Int -> Origin -> ShowS
Prelude.Show, (forall x. Origin -> Rep Origin x)
-> (forall x. Rep Origin x -> Origin) -> Generic Origin
forall x. Rep Origin x -> Origin
forall x. Origin -> Rep Origin x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Origin x -> Origin
$cfrom :: forall x. Origin -> Rep Origin x
Prelude.Generic)

-- |
-- Create a value of 'Origin' 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:
--
-- 'regionName', 'origin_regionName' - The AWS Region name of the origin resource.
--
-- 'resourceType', 'origin_resourceType' - The resource type of the origin resource (e.g., /Instance/).
--
-- 'name', 'origin_name' - The name of the origin resource.
--
-- 'protocolPolicy', 'origin_protocolPolicy' - The protocol that your Amazon Lightsail distribution uses when
-- establishing a connection with your origin to pull content.
newOrigin ::
  Origin
newOrigin :: Origin
newOrigin =
  Origin' :: Maybe RegionName
-> Maybe ResourceType
-> Maybe Text
-> Maybe OriginProtocolPolicyEnum
-> Origin
Origin'
    { $sel:regionName:Origin' :: Maybe RegionName
regionName = Maybe RegionName
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:Origin' :: Maybe ResourceType
resourceType = Maybe ResourceType
forall a. Maybe a
Prelude.Nothing,
      $sel:name:Origin' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:protocolPolicy:Origin' :: Maybe OriginProtocolPolicyEnum
protocolPolicy = Maybe OriginProtocolPolicyEnum
forall a. Maybe a
Prelude.Nothing
    }

-- | The AWS Region name of the origin resource.
origin_regionName :: Lens.Lens' Origin (Prelude.Maybe RegionName)
origin_regionName :: (Maybe RegionName -> f (Maybe RegionName)) -> Origin -> f Origin
origin_regionName = (Origin -> Maybe RegionName)
-> (Origin -> Maybe RegionName -> Origin)
-> Lens Origin Origin (Maybe RegionName) (Maybe RegionName)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Origin' {Maybe RegionName
regionName :: Maybe RegionName
$sel:regionName:Origin' :: Origin -> Maybe RegionName
regionName} -> Maybe RegionName
regionName) (\s :: Origin
s@Origin' {} Maybe RegionName
a -> Origin
s {$sel:regionName:Origin' :: Maybe RegionName
regionName = Maybe RegionName
a} :: Origin)

-- | The resource type of the origin resource (e.g., /Instance/).
origin_resourceType :: Lens.Lens' Origin (Prelude.Maybe ResourceType)
origin_resourceType :: (Maybe ResourceType -> f (Maybe ResourceType))
-> Origin -> f Origin
origin_resourceType = (Origin -> Maybe ResourceType)
-> (Origin -> Maybe ResourceType -> Origin)
-> Lens Origin Origin (Maybe ResourceType) (Maybe ResourceType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Origin' {Maybe ResourceType
resourceType :: Maybe ResourceType
$sel:resourceType:Origin' :: Origin -> Maybe ResourceType
resourceType} -> Maybe ResourceType
resourceType) (\s :: Origin
s@Origin' {} Maybe ResourceType
a -> Origin
s {$sel:resourceType:Origin' :: Maybe ResourceType
resourceType = Maybe ResourceType
a} :: Origin)

-- | The name of the origin resource.
origin_name :: Lens.Lens' Origin (Prelude.Maybe Prelude.Text)
origin_name :: (Maybe Text -> f (Maybe Text)) -> Origin -> f Origin
origin_name = (Origin -> Maybe Text)
-> (Origin -> Maybe Text -> Origin)
-> Lens Origin Origin (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Origin' {Maybe Text
name :: Maybe Text
$sel:name:Origin' :: Origin -> Maybe Text
name} -> Maybe Text
name) (\s :: Origin
s@Origin' {} Maybe Text
a -> Origin
s {$sel:name:Origin' :: Maybe Text
name = Maybe Text
a} :: Origin)

-- | The protocol that your Amazon Lightsail distribution uses when
-- establishing a connection with your origin to pull content.
origin_protocolPolicy :: Lens.Lens' Origin (Prelude.Maybe OriginProtocolPolicyEnum)
origin_protocolPolicy :: (Maybe OriginProtocolPolicyEnum
 -> f (Maybe OriginProtocolPolicyEnum))
-> Origin -> f Origin
origin_protocolPolicy = (Origin -> Maybe OriginProtocolPolicyEnum)
-> (Origin -> Maybe OriginProtocolPolicyEnum -> Origin)
-> Lens
     Origin
     Origin
     (Maybe OriginProtocolPolicyEnum)
     (Maybe OriginProtocolPolicyEnum)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Origin' {Maybe OriginProtocolPolicyEnum
protocolPolicy :: Maybe OriginProtocolPolicyEnum
$sel:protocolPolicy:Origin' :: Origin -> Maybe OriginProtocolPolicyEnum
protocolPolicy} -> Maybe OriginProtocolPolicyEnum
protocolPolicy) (\s :: Origin
s@Origin' {} Maybe OriginProtocolPolicyEnum
a -> Origin
s {$sel:protocolPolicy:Origin' :: Maybe OriginProtocolPolicyEnum
protocolPolicy = Maybe OriginProtocolPolicyEnum
a} :: Origin)

instance Core.FromJSON Origin where
  parseJSON :: Value -> Parser Origin
parseJSON =
    String -> (Object -> Parser Origin) -> Value -> Parser Origin
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Origin"
      ( \Object
x ->
          Maybe RegionName
-> Maybe ResourceType
-> Maybe Text
-> Maybe OriginProtocolPolicyEnum
-> Origin
Origin'
            (Maybe RegionName
 -> Maybe ResourceType
 -> Maybe Text
 -> Maybe OriginProtocolPolicyEnum
 -> Origin)
-> Parser (Maybe RegionName)
-> Parser
     (Maybe ResourceType
      -> Maybe Text -> Maybe OriginProtocolPolicyEnum -> Origin)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe RegionName)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"regionName")
            Parser
  (Maybe ResourceType
   -> Maybe Text -> Maybe OriginProtocolPolicyEnum -> Origin)
-> Parser (Maybe ResourceType)
-> Parser (Maybe Text -> Maybe OriginProtocolPolicyEnum -> Origin)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe ResourceType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"resourceType")
            Parser (Maybe Text -> Maybe OriginProtocolPolicyEnum -> Origin)
-> Parser (Maybe Text)
-> Parser (Maybe OriginProtocolPolicyEnum -> Origin)
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
"name")
            Parser (Maybe OriginProtocolPolicyEnum -> Origin)
-> Parser (Maybe OriginProtocolPolicyEnum) -> Parser Origin
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe OriginProtocolPolicyEnum)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"protocolPolicy")
      )

instance Prelude.Hashable Origin

instance Prelude.NFData Origin