{-# 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.Transfer.Types.HomeDirectoryMapEntry
-- 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.Transfer.Types.HomeDirectoryMapEntry where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents an object that contains entries and targets for
-- @HomeDirectoryMappings@.
--
-- The following is an @Entry@ and @Target@ pair example for @chroot@.
--
-- @[ { \"Entry:\": \"\/\", \"Target\": \"\/bucket_name\/home\/mydirectory\" } ]@
--
-- If the target of a logical directory entry does not exist in Amazon S3
-- or EFS, the entry is ignored. As a workaround, you can use the Amazon S3
-- API or EFS API to create 0 byte objects as place holders for your
-- directory. If using the CLI, use the @s3api@ or @efsapi@ call instead of
-- @s3@ or @efs@ so you can use the put-object operation. For example, you
-- use the following:
-- @aws s3api put-object --bucket bucketname --key path\/to\/folder\/@.
-- Make sure that the end of the key name ends in a @\/@ for it to be
-- considered a folder.
--
-- /See:/ 'newHomeDirectoryMapEntry' smart constructor.
data HomeDirectoryMapEntry = HomeDirectoryMapEntry'
  { -- | Represents an entry for @HomeDirectoryMappings@.
    HomeDirectoryMapEntry -> Text
entry :: Prelude.Text,
    -- | Represents the map target that is used in a @HomeDirectorymapEntry@.
    HomeDirectoryMapEntry -> Text
target :: Prelude.Text
  }
  deriving (HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool
(HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool)
-> (HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool)
-> Eq HomeDirectoryMapEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool
$c/= :: HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool
== :: HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool
$c== :: HomeDirectoryMapEntry -> HomeDirectoryMapEntry -> Bool
Prelude.Eq, ReadPrec [HomeDirectoryMapEntry]
ReadPrec HomeDirectoryMapEntry
Int -> ReadS HomeDirectoryMapEntry
ReadS [HomeDirectoryMapEntry]
(Int -> ReadS HomeDirectoryMapEntry)
-> ReadS [HomeDirectoryMapEntry]
-> ReadPrec HomeDirectoryMapEntry
-> ReadPrec [HomeDirectoryMapEntry]
-> Read HomeDirectoryMapEntry
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [HomeDirectoryMapEntry]
$creadListPrec :: ReadPrec [HomeDirectoryMapEntry]
readPrec :: ReadPrec HomeDirectoryMapEntry
$creadPrec :: ReadPrec HomeDirectoryMapEntry
readList :: ReadS [HomeDirectoryMapEntry]
$creadList :: ReadS [HomeDirectoryMapEntry]
readsPrec :: Int -> ReadS HomeDirectoryMapEntry
$creadsPrec :: Int -> ReadS HomeDirectoryMapEntry
Prelude.Read, Int -> HomeDirectoryMapEntry -> ShowS
[HomeDirectoryMapEntry] -> ShowS
HomeDirectoryMapEntry -> String
(Int -> HomeDirectoryMapEntry -> ShowS)
-> (HomeDirectoryMapEntry -> String)
-> ([HomeDirectoryMapEntry] -> ShowS)
-> Show HomeDirectoryMapEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HomeDirectoryMapEntry] -> ShowS
$cshowList :: [HomeDirectoryMapEntry] -> ShowS
show :: HomeDirectoryMapEntry -> String
$cshow :: HomeDirectoryMapEntry -> String
showsPrec :: Int -> HomeDirectoryMapEntry -> ShowS
$cshowsPrec :: Int -> HomeDirectoryMapEntry -> ShowS
Prelude.Show, (forall x. HomeDirectoryMapEntry -> Rep HomeDirectoryMapEntry x)
-> (forall x. Rep HomeDirectoryMapEntry x -> HomeDirectoryMapEntry)
-> Generic HomeDirectoryMapEntry
forall x. Rep HomeDirectoryMapEntry x -> HomeDirectoryMapEntry
forall x. HomeDirectoryMapEntry -> Rep HomeDirectoryMapEntry x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep HomeDirectoryMapEntry x -> HomeDirectoryMapEntry
$cfrom :: forall x. HomeDirectoryMapEntry -> Rep HomeDirectoryMapEntry x
Prelude.Generic)

-- |
-- Create a value of 'HomeDirectoryMapEntry' 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:
--
-- 'entry', 'homeDirectoryMapEntry_entry' - Represents an entry for @HomeDirectoryMappings@.
--
-- 'target', 'homeDirectoryMapEntry_target' - Represents the map target that is used in a @HomeDirectorymapEntry@.
newHomeDirectoryMapEntry ::
  -- | 'entry'
  Prelude.Text ->
  -- | 'target'
  Prelude.Text ->
  HomeDirectoryMapEntry
newHomeDirectoryMapEntry :: Text -> Text -> HomeDirectoryMapEntry
newHomeDirectoryMapEntry Text
pEntry_ Text
pTarget_ =
  HomeDirectoryMapEntry' :: Text -> Text -> HomeDirectoryMapEntry
HomeDirectoryMapEntry'
    { $sel:entry:HomeDirectoryMapEntry' :: Text
entry = Text
pEntry_,
      $sel:target:HomeDirectoryMapEntry' :: Text
target = Text
pTarget_
    }

-- | Represents an entry for @HomeDirectoryMappings@.
homeDirectoryMapEntry_entry :: Lens.Lens' HomeDirectoryMapEntry Prelude.Text
homeDirectoryMapEntry_entry :: (Text -> f Text)
-> HomeDirectoryMapEntry -> f HomeDirectoryMapEntry
homeDirectoryMapEntry_entry = (HomeDirectoryMapEntry -> Text)
-> (HomeDirectoryMapEntry -> Text -> HomeDirectoryMapEntry)
-> Lens HomeDirectoryMapEntry HomeDirectoryMapEntry Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HomeDirectoryMapEntry' {Text
entry :: Text
$sel:entry:HomeDirectoryMapEntry' :: HomeDirectoryMapEntry -> Text
entry} -> Text
entry) (\s :: HomeDirectoryMapEntry
s@HomeDirectoryMapEntry' {} Text
a -> HomeDirectoryMapEntry
s {$sel:entry:HomeDirectoryMapEntry' :: Text
entry = Text
a} :: HomeDirectoryMapEntry)

-- | Represents the map target that is used in a @HomeDirectorymapEntry@.
homeDirectoryMapEntry_target :: Lens.Lens' HomeDirectoryMapEntry Prelude.Text
homeDirectoryMapEntry_target :: (Text -> f Text)
-> HomeDirectoryMapEntry -> f HomeDirectoryMapEntry
homeDirectoryMapEntry_target = (HomeDirectoryMapEntry -> Text)
-> (HomeDirectoryMapEntry -> Text -> HomeDirectoryMapEntry)
-> Lens HomeDirectoryMapEntry HomeDirectoryMapEntry Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\HomeDirectoryMapEntry' {Text
target :: Text
$sel:target:HomeDirectoryMapEntry' :: HomeDirectoryMapEntry -> Text
target} -> Text
target) (\s :: HomeDirectoryMapEntry
s@HomeDirectoryMapEntry' {} Text
a -> HomeDirectoryMapEntry
s {$sel:target:HomeDirectoryMapEntry' :: Text
target = Text
a} :: HomeDirectoryMapEntry)

instance Core.FromJSON HomeDirectoryMapEntry where
  parseJSON :: Value -> Parser HomeDirectoryMapEntry
parseJSON =
    String
-> (Object -> Parser HomeDirectoryMapEntry)
-> Value
-> Parser HomeDirectoryMapEntry
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"HomeDirectoryMapEntry"
      ( \Object
x ->
          Text -> Text -> HomeDirectoryMapEntry
HomeDirectoryMapEntry'
            (Text -> Text -> HomeDirectoryMapEntry)
-> Parser Text -> Parser (Text -> HomeDirectoryMapEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Entry") Parser (Text -> HomeDirectoryMapEntry)
-> Parser Text -> Parser HomeDirectoryMapEntry
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Target")
      )

instance Prelude.Hashable HomeDirectoryMapEntry

instance Prelude.NFData HomeDirectoryMapEntry

instance Core.ToJSON HomeDirectoryMapEntry where
  toJSON :: HomeDirectoryMapEntry -> Value
toJSON HomeDirectoryMapEntry' {Text
target :: Text
entry :: Text
$sel:target:HomeDirectoryMapEntry' :: HomeDirectoryMapEntry -> Text
$sel:entry:HomeDirectoryMapEntry' :: HomeDirectoryMapEntry -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Entry" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
entry),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Target" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
target)
          ]
      )