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

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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, bucket, 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 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,
    -- | 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
  }
  deriving (Origin -> Origin -> Bool
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]
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
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. 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:
--
-- '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.
--
-- 'regionName', 'origin_regionName' - The AWS Region name of the origin resource.
--
-- 'resourceType', 'origin_resourceType' - The resource type of the origin resource (e.g., /Instance/).
newOrigin ::
  Origin
newOrigin :: Origin
newOrigin =
  Origin'
    { $sel:name:Origin' :: Maybe Text
name = forall a. Maybe a
Prelude.Nothing,
      $sel:protocolPolicy:Origin' :: Maybe OriginProtocolPolicyEnum
protocolPolicy = forall a. Maybe a
Prelude.Nothing,
      $sel:regionName:Origin' :: Maybe RegionName
regionName = forall a. Maybe a
Prelude.Nothing,
      $sel:resourceType:Origin' :: Maybe ResourceType
resourceType = forall a. Maybe a
Prelude.Nothing
    }

-- | The name of the origin resource.
origin_name :: Lens.Lens' Origin (Prelude.Maybe Prelude.Text)
origin_name :: Lens' Origin (Maybe Text)
origin_name = 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 :: Lens' Origin (Maybe OriginProtocolPolicyEnum)
origin_protocolPolicy = 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)

-- | The AWS Region name of the origin resource.
origin_regionName :: Lens.Lens' Origin (Prelude.Maybe RegionName)
origin_regionName :: Lens' Origin (Maybe RegionName)
origin_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 :: Lens' Origin (Maybe ResourceType)
origin_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)

instance Data.FromJSON Origin where
  parseJSON :: Value -> Parser Origin
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Origin"
      ( \Object
x ->
          Maybe Text
-> Maybe OriginProtocolPolicyEnum
-> Maybe RegionName
-> Maybe ResourceType
-> Origin
Origin'
            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
"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
"protocolPolicy")
            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
"regionName")
            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
"resourceType")
      )

instance Prelude.Hashable Origin where
  hashWithSalt :: Int -> Origin -> Int
hashWithSalt Int
_salt Origin' {Maybe Text
Maybe OriginProtocolPolicyEnum
Maybe RegionName
Maybe ResourceType
resourceType :: Maybe ResourceType
regionName :: Maybe RegionName
protocolPolicy :: Maybe OriginProtocolPolicyEnum
name :: Maybe Text
$sel:resourceType:Origin' :: Origin -> Maybe ResourceType
$sel:regionName:Origin' :: Origin -> Maybe RegionName
$sel:protocolPolicy:Origin' :: Origin -> Maybe OriginProtocolPolicyEnum
$sel:name:Origin' :: Origin -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe OriginProtocolPolicyEnum
protocolPolicy
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe RegionName
regionName
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe ResourceType
resourceType

instance Prelude.NFData Origin where
  rnf :: Origin -> ()
rnf Origin' {Maybe Text
Maybe OriginProtocolPolicyEnum
Maybe RegionName
Maybe ResourceType
resourceType :: Maybe ResourceType
regionName :: Maybe RegionName
protocolPolicy :: Maybe OriginProtocolPolicyEnum
name :: Maybe Text
$sel:resourceType:Origin' :: Origin -> Maybe ResourceType
$sel:regionName:Origin' :: Origin -> Maybe RegionName
$sel:protocolPolicy:Origin' :: Origin -> Maybe OriginProtocolPolicyEnum
$sel:name:Origin' :: Origin -> Maybe Text
..} =
    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 OriginProtocolPolicyEnum
protocolPolicy
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe RegionName
regionName
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe ResourceType
resourceType