{-# 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.CodeCommit.Types.Location
-- 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.CodeCommit.Types.Location where

import Amazonka.CodeCommit.Types.RelativeFileVersionEnum
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Returns information about the location of a change or comment in the
-- comparison between two commits or a pull request.
--
-- /See:/ 'newLocation' smart constructor.
data Location = Location'
  { -- | In a comparison of commits or a pull request, whether the change is in
    -- the before or after of that comparison.
    Location -> Maybe RelativeFileVersionEnum
relativeFileVersion :: Prelude.Maybe RelativeFileVersionEnum,
    -- | The name of the file being compared, including its extension and
    -- subdirectory, if any.
    Location -> Maybe Text
filePath :: Prelude.Maybe Prelude.Text,
    -- | The position of a change in a compared file, in line number format.
    Location -> Maybe Integer
filePosition :: Prelude.Maybe Prelude.Integer
  }
  deriving (Location -> Location -> Bool
(Location -> Location -> Bool)
-> (Location -> Location -> Bool) -> Eq Location
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Location -> Location -> Bool
$c/= :: Location -> Location -> Bool
== :: Location -> Location -> Bool
$c== :: Location -> Location -> Bool
Prelude.Eq, ReadPrec [Location]
ReadPrec Location
Int -> ReadS Location
ReadS [Location]
(Int -> ReadS Location)
-> ReadS [Location]
-> ReadPrec Location
-> ReadPrec [Location]
-> Read Location
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Location]
$creadListPrec :: ReadPrec [Location]
readPrec :: ReadPrec Location
$creadPrec :: ReadPrec Location
readList :: ReadS [Location]
$creadList :: ReadS [Location]
readsPrec :: Int -> ReadS Location
$creadsPrec :: Int -> ReadS Location
Prelude.Read, Int -> Location -> ShowS
[Location] -> ShowS
Location -> String
(Int -> Location -> ShowS)
-> (Location -> String) -> ([Location] -> ShowS) -> Show Location
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Location] -> ShowS
$cshowList :: [Location] -> ShowS
show :: Location -> String
$cshow :: Location -> String
showsPrec :: Int -> Location -> ShowS
$cshowsPrec :: Int -> Location -> ShowS
Prelude.Show, (forall x. Location -> Rep Location x)
-> (forall x. Rep Location x -> Location) -> Generic Location
forall x. Rep Location x -> Location
forall x. Location -> Rep Location x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Location x -> Location
$cfrom :: forall x. Location -> Rep Location x
Prelude.Generic)

-- |
-- Create a value of 'Location' 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:
--
-- 'relativeFileVersion', 'location_relativeFileVersion' - In a comparison of commits or a pull request, whether the change is in
-- the before or after of that comparison.
--
-- 'filePath', 'location_filePath' - The name of the file being compared, including its extension and
-- subdirectory, if any.
--
-- 'filePosition', 'location_filePosition' - The position of a change in a compared file, in line number format.
newLocation ::
  Location
newLocation :: Location
newLocation =
  Location' :: Maybe RelativeFileVersionEnum
-> Maybe Text -> Maybe Integer -> Location
Location'
    { $sel:relativeFileVersion:Location' :: Maybe RelativeFileVersionEnum
relativeFileVersion = Maybe RelativeFileVersionEnum
forall a. Maybe a
Prelude.Nothing,
      $sel:filePath:Location' :: Maybe Text
filePath = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:filePosition:Location' :: Maybe Integer
filePosition = Maybe Integer
forall a. Maybe a
Prelude.Nothing
    }

-- | In a comparison of commits or a pull request, whether the change is in
-- the before or after of that comparison.
location_relativeFileVersion :: Lens.Lens' Location (Prelude.Maybe RelativeFileVersionEnum)
location_relativeFileVersion :: (Maybe RelativeFileVersionEnum
 -> f (Maybe RelativeFileVersionEnum))
-> Location -> f Location
location_relativeFileVersion = (Location -> Maybe RelativeFileVersionEnum)
-> (Location -> Maybe RelativeFileVersionEnum -> Location)
-> Lens
     Location
     Location
     (Maybe RelativeFileVersionEnum)
     (Maybe RelativeFileVersionEnum)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Maybe RelativeFileVersionEnum
relativeFileVersion :: Maybe RelativeFileVersionEnum
$sel:relativeFileVersion:Location' :: Location -> Maybe RelativeFileVersionEnum
relativeFileVersion} -> Maybe RelativeFileVersionEnum
relativeFileVersion) (\s :: Location
s@Location' {} Maybe RelativeFileVersionEnum
a -> Location
s {$sel:relativeFileVersion:Location' :: Maybe RelativeFileVersionEnum
relativeFileVersion = Maybe RelativeFileVersionEnum
a} :: Location)

-- | The name of the file being compared, including its extension and
-- subdirectory, if any.
location_filePath :: Lens.Lens' Location (Prelude.Maybe Prelude.Text)
location_filePath :: (Maybe Text -> f (Maybe Text)) -> Location -> f Location
location_filePath = (Location -> Maybe Text)
-> (Location -> Maybe Text -> Location)
-> Lens Location Location (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Maybe Text
filePath :: Maybe Text
$sel:filePath:Location' :: Location -> Maybe Text
filePath} -> Maybe Text
filePath) (\s :: Location
s@Location' {} Maybe Text
a -> Location
s {$sel:filePath:Location' :: Maybe Text
filePath = Maybe Text
a} :: Location)

-- | The position of a change in a compared file, in line number format.
location_filePosition :: Lens.Lens' Location (Prelude.Maybe Prelude.Integer)
location_filePosition :: (Maybe Integer -> f (Maybe Integer)) -> Location -> f Location
location_filePosition = (Location -> Maybe Integer)
-> (Location -> Maybe Integer -> Location)
-> Lens Location Location (Maybe Integer) (Maybe Integer)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Location' {Maybe Integer
filePosition :: Maybe Integer
$sel:filePosition:Location' :: Location -> Maybe Integer
filePosition} -> Maybe Integer
filePosition) (\s :: Location
s@Location' {} Maybe Integer
a -> Location
s {$sel:filePosition:Location' :: Maybe Integer
filePosition = Maybe Integer
a} :: Location)

instance Core.FromJSON Location where
  parseJSON :: Value -> Parser Location
parseJSON =
    String -> (Object -> Parser Location) -> Value -> Parser Location
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"Location"
      ( \Object
x ->
          Maybe RelativeFileVersionEnum
-> Maybe Text -> Maybe Integer -> Location
Location'
            (Maybe RelativeFileVersionEnum
 -> Maybe Text -> Maybe Integer -> Location)
-> Parser (Maybe RelativeFileVersionEnum)
-> Parser (Maybe Text -> Maybe Integer -> Location)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe RelativeFileVersionEnum)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"relativeFileVersion")
            Parser (Maybe Text -> Maybe Integer -> Location)
-> Parser (Maybe Text) -> Parser (Maybe Integer -> Location)
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
"filePath")
            Parser (Maybe Integer -> Location)
-> Parser (Maybe Integer) -> Parser Location
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Integer)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"filePosition")
      )

instance Prelude.Hashable Location

instance Prelude.NFData Location

instance Core.ToJSON Location where
  toJSON :: Location -> Value
toJSON Location' {Maybe Integer
Maybe Text
Maybe RelativeFileVersionEnum
filePosition :: Maybe Integer
filePath :: Maybe Text
relativeFileVersion :: Maybe RelativeFileVersionEnum
$sel:filePosition:Location' :: Location -> Maybe Integer
$sel:filePath:Location' :: Location -> Maybe Text
$sel:relativeFileVersion:Location' :: Location -> Maybe RelativeFileVersionEnum
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"relativeFileVersion" Text -> RelativeFileVersionEnum -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (RelativeFileVersionEnum -> Pair)
-> Maybe RelativeFileVersionEnum -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe RelativeFileVersionEnum
relativeFileVersion,
            (Text
"filePath" 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
filePath,
            (Text
"filePosition" Text -> Integer -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Integer -> Pair) -> Maybe Integer -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Integer
filePosition
          ]
      )