{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Events.PullRequestReviewEvent where

import           Data.Aeson                (FromJSON (..), ToJSON (..), object)
import           Data.Aeson.Types          (Value (..), (.:), (.:?), (.=))
import           Data.Text                 (Text)
import           Test.QuickCheck.Arbitrary (Arbitrary (..))

import           GitHub.Types.Base
import           GitHub.Types.Event


data PullRequestReviewEvent = PullRequestReviewEvent
    { PullRequestReviewEvent -> Maybe Installation
pullRequestReviewEventInstallation :: Maybe Installation
    , PullRequestReviewEvent -> Organization
pullRequestReviewEventOrganization :: Organization
    , PullRequestReviewEvent -> Repository
pullRequestReviewEventRepository   :: Repository
    , PullRequestReviewEvent -> User
pullRequestReviewEventSender       :: User

    , PullRequestReviewEvent -> Text
pullRequestReviewEventAction       :: Text
    , PullRequestReviewEvent -> Maybe Changes
pullRequestReviewEventChanges      :: Maybe Changes
    , PullRequestReviewEvent -> SimplePullRequest
pullRequestReviewEventPullRequest  :: SimplePullRequest
    , PullRequestReviewEvent -> Review
pullRequestReviewEventReview       :: Review
    } deriving (PullRequestReviewEvent -> PullRequestReviewEvent -> Bool
(PullRequestReviewEvent -> PullRequestReviewEvent -> Bool)
-> (PullRequestReviewEvent -> PullRequestReviewEvent -> Bool)
-> Eq PullRequestReviewEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PullRequestReviewEvent -> PullRequestReviewEvent -> Bool
$c/= :: PullRequestReviewEvent -> PullRequestReviewEvent -> Bool
== :: PullRequestReviewEvent -> PullRequestReviewEvent -> Bool
$c== :: PullRequestReviewEvent -> PullRequestReviewEvent -> Bool
Eq, Int -> PullRequestReviewEvent -> ShowS
[PullRequestReviewEvent] -> ShowS
PullRequestReviewEvent -> String
(Int -> PullRequestReviewEvent -> ShowS)
-> (PullRequestReviewEvent -> String)
-> ([PullRequestReviewEvent] -> ShowS)
-> Show PullRequestReviewEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PullRequestReviewEvent] -> ShowS
$cshowList :: [PullRequestReviewEvent] -> ShowS
show :: PullRequestReviewEvent -> String
$cshow :: PullRequestReviewEvent -> String
showsPrec :: Int -> PullRequestReviewEvent -> ShowS
$cshowsPrec :: Int -> PullRequestReviewEvent -> ShowS
Show, ReadPrec [PullRequestReviewEvent]
ReadPrec PullRequestReviewEvent
Int -> ReadS PullRequestReviewEvent
ReadS [PullRequestReviewEvent]
(Int -> ReadS PullRequestReviewEvent)
-> ReadS [PullRequestReviewEvent]
-> ReadPrec PullRequestReviewEvent
-> ReadPrec [PullRequestReviewEvent]
-> Read PullRequestReviewEvent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [PullRequestReviewEvent]
$creadListPrec :: ReadPrec [PullRequestReviewEvent]
readPrec :: ReadPrec PullRequestReviewEvent
$creadPrec :: ReadPrec PullRequestReviewEvent
readList :: ReadS [PullRequestReviewEvent]
$creadList :: ReadS [PullRequestReviewEvent]
readsPrec :: Int -> ReadS PullRequestReviewEvent
$creadsPrec :: Int -> ReadS PullRequestReviewEvent
Read)

instance Event PullRequestReviewEvent where
    typeName :: TypeName PullRequestReviewEvent
typeName = Text -> TypeName PullRequestReviewEvent
forall a. Text -> TypeName a
TypeName Text
"PullRequestReviewEvent"
    eventName :: EventName PullRequestReviewEvent
eventName = Text -> EventName PullRequestReviewEvent
forall a. Text -> EventName a
EventName Text
"pull_request_review"

instance FromJSON PullRequestReviewEvent where
    parseJSON :: Value -> Parser PullRequestReviewEvent
parseJSON (Object Object
x) = Maybe Installation
-> Organization
-> Repository
-> User
-> Text
-> Maybe Changes
-> SimplePullRequest
-> Review
-> PullRequestReviewEvent
PullRequestReviewEvent
        (Maybe Installation
 -> Organization
 -> Repository
 -> User
 -> Text
 -> Maybe Changes
 -> SimplePullRequest
 -> Review
 -> PullRequestReviewEvent)
-> Parser (Maybe Installation)
-> Parser
     (Organization
      -> Repository
      -> User
      -> Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
x Object -> Key -> Parser (Maybe Installation)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"installation"
        Parser
  (Organization
   -> Repository
   -> User
   -> Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Parser Organization
-> Parser
     (Repository
      -> User
      -> Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Organization
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"organization"
        Parser
  (Repository
   -> User
   -> Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Parser Repository
-> Parser
     (User
      -> Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Repository
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"repository"
        Parser
  (User
   -> Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Parser User
-> Parser
     (Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser User
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"sender"

        Parser
  (Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Parser Text
-> Parser
     (Maybe Changes
      -> SimplePullRequest -> Review -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Text
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"action"
        Parser
  (Maybe Changes
   -> SimplePullRequest -> Review -> PullRequestReviewEvent)
-> Parser (Maybe Changes)
-> Parser (SimplePullRequest -> Review -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe Changes)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"changes"
        Parser (SimplePullRequest -> Review -> PullRequestReviewEvent)
-> Parser SimplePullRequest
-> Parser (Review -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser SimplePullRequest
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"pull_request"
        Parser (Review -> PullRequestReviewEvent)
-> Parser Review -> Parser PullRequestReviewEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Review
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"review"

    parseJSON Value
_ = String -> Parser PullRequestReviewEvent
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"PullRequestReviewEvent"

instance ToJSON PullRequestReviewEvent where
    toJSON :: PullRequestReviewEvent -> Value
toJSON PullRequestReviewEvent{Maybe Changes
Maybe Installation
Text
Organization
User
Review
Repository
SimplePullRequest
pullRequestReviewEventReview :: Review
pullRequestReviewEventPullRequest :: SimplePullRequest
pullRequestReviewEventChanges :: Maybe Changes
pullRequestReviewEventAction :: Text
pullRequestReviewEventSender :: User
pullRequestReviewEventRepository :: Repository
pullRequestReviewEventOrganization :: Organization
pullRequestReviewEventInstallation :: Maybe Installation
pullRequestReviewEventReview :: PullRequestReviewEvent -> Review
pullRequestReviewEventPullRequest :: PullRequestReviewEvent -> SimplePullRequest
pullRequestReviewEventChanges :: PullRequestReviewEvent -> Maybe Changes
pullRequestReviewEventAction :: PullRequestReviewEvent -> Text
pullRequestReviewEventSender :: PullRequestReviewEvent -> User
pullRequestReviewEventRepository :: PullRequestReviewEvent -> Repository
pullRequestReviewEventOrganization :: PullRequestReviewEvent -> Organization
pullRequestReviewEventInstallation :: PullRequestReviewEvent -> Maybe Installation
..} = [Pair] -> Value
object
        [ Key
"installation" Key -> Maybe Installation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Installation
pullRequestReviewEventInstallation
        , Key
"organization" Key -> Organization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Organization
pullRequestReviewEventOrganization
        , Key
"repository"   Key -> Repository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Repository
pullRequestReviewEventRepository
        , Key
"sender"       Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
pullRequestReviewEventSender

        , Key
"action"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
pullRequestReviewEventAction
        , Key
"changes"      Key -> Maybe Changes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Changes
pullRequestReviewEventChanges
        , Key
"pull_request" Key -> SimplePullRequest -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= SimplePullRequest
pullRequestReviewEventPullRequest
        , Key
"review"       Key -> Review -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Review
pullRequestReviewEventReview
        ]


instance Arbitrary PullRequestReviewEvent where
    arbitrary :: Gen PullRequestReviewEvent
arbitrary = Maybe Installation
-> Organization
-> Repository
-> User
-> Text
-> Maybe Changes
-> SimplePullRequest
-> Review
-> PullRequestReviewEvent
PullRequestReviewEvent
        (Maybe Installation
 -> Organization
 -> Repository
 -> User
 -> Text
 -> Maybe Changes
 -> SimplePullRequest
 -> Review
 -> PullRequestReviewEvent)
-> Gen (Maybe Installation)
-> Gen
     (Organization
      -> Repository
      -> User
      -> Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Maybe Installation)
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (Organization
   -> Repository
   -> User
   -> Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Gen Organization
-> Gen
     (Repository
      -> User
      -> Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Organization
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (Repository
   -> User
   -> Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Gen Repository
-> Gen
     (User
      -> Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Repository
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (User
   -> Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Gen User
-> Gen
     (Text
      -> Maybe Changes
      -> SimplePullRequest
      -> Review
      -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen User
forall a. Arbitrary a => Gen a
arbitrary

        Gen
  (Text
   -> Maybe Changes
   -> SimplePullRequest
   -> Review
   -> PullRequestReviewEvent)
-> Gen Text
-> Gen
     (Maybe Changes
      -> SimplePullRequest -> Review -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (Maybe Changes
   -> SimplePullRequest -> Review -> PullRequestReviewEvent)
-> Gen (Maybe Changes)
-> Gen (SimplePullRequest -> Review -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe Changes)
forall a. Arbitrary a => Gen a
arbitrary
        Gen (SimplePullRequest -> Review -> PullRequestReviewEvent)
-> Gen SimplePullRequest -> Gen (Review -> PullRequestReviewEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen SimplePullRequest
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Review -> PullRequestReviewEvent)
-> Gen Review -> Gen PullRequestReviewEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Review
forall a. Arbitrary a => Gen a
arbitrary