{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Events.WorkflowJobEvent 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 WorkflowJobEvent = WorkflowJobEvent
    { WorkflowJobEvent -> Maybe Installation
workflowJobEventInstallation :: Maybe Installation
    , WorkflowJobEvent -> Organization
workflowJobEventOrganization :: Organization
    , WorkflowJobEvent -> Repository
workflowJobEventRepository   :: Repository
    , WorkflowJobEvent -> User
workflowJobEventSender       :: User

    , WorkflowJobEvent -> Text
workflowJobEventAction       :: Text
    , WorkflowJobEvent -> WorkflowJob
workflowJobEventWorkflowJob  :: WorkflowJob
    } deriving (WorkflowJobEvent -> WorkflowJobEvent -> Bool
(WorkflowJobEvent -> WorkflowJobEvent -> Bool)
-> (WorkflowJobEvent -> WorkflowJobEvent -> Bool)
-> Eq WorkflowJobEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WorkflowJobEvent -> WorkflowJobEvent -> Bool
$c/= :: WorkflowJobEvent -> WorkflowJobEvent -> Bool
== :: WorkflowJobEvent -> WorkflowJobEvent -> Bool
$c== :: WorkflowJobEvent -> WorkflowJobEvent -> Bool
Eq, Int -> WorkflowJobEvent -> ShowS
[WorkflowJobEvent] -> ShowS
WorkflowJobEvent -> String
(Int -> WorkflowJobEvent -> ShowS)
-> (WorkflowJobEvent -> String)
-> ([WorkflowJobEvent] -> ShowS)
-> Show WorkflowJobEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WorkflowJobEvent] -> ShowS
$cshowList :: [WorkflowJobEvent] -> ShowS
show :: WorkflowJobEvent -> String
$cshow :: WorkflowJobEvent -> String
showsPrec :: Int -> WorkflowJobEvent -> ShowS
$cshowsPrec :: Int -> WorkflowJobEvent -> ShowS
Show, ReadPrec [WorkflowJobEvent]
ReadPrec WorkflowJobEvent
Int -> ReadS WorkflowJobEvent
ReadS [WorkflowJobEvent]
(Int -> ReadS WorkflowJobEvent)
-> ReadS [WorkflowJobEvent]
-> ReadPrec WorkflowJobEvent
-> ReadPrec [WorkflowJobEvent]
-> Read WorkflowJobEvent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WorkflowJobEvent]
$creadListPrec :: ReadPrec [WorkflowJobEvent]
readPrec :: ReadPrec WorkflowJobEvent
$creadPrec :: ReadPrec WorkflowJobEvent
readList :: ReadS [WorkflowJobEvent]
$creadList :: ReadS [WorkflowJobEvent]
readsPrec :: Int -> ReadS WorkflowJobEvent
$creadsPrec :: Int -> ReadS WorkflowJobEvent
Read)

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

instance FromJSON WorkflowJobEvent where
    parseJSON :: Value -> Parser WorkflowJobEvent
parseJSON (Object Object
x) = Maybe Installation
-> Organization
-> Repository
-> User
-> Text
-> WorkflowJob
-> WorkflowJobEvent
WorkflowJobEvent
        (Maybe Installation
 -> Organization
 -> Repository
 -> User
 -> Text
 -> WorkflowJob
 -> WorkflowJobEvent)
-> Parser (Maybe Installation)
-> Parser
     (Organization
      -> Repository -> User -> Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Parser Organization
-> Parser
     (Repository -> User -> Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Parser Repository
-> Parser (User -> Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Parser User -> Parser (Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Parser Text -> Parser (WorkflowJob -> WorkflowJobEvent)
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 (WorkflowJob -> WorkflowJobEvent)
-> Parser WorkflowJob -> Parser WorkflowJobEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser WorkflowJob
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"workflow_job"

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

instance ToJSON WorkflowJobEvent where
    toJSON :: WorkflowJobEvent -> Value
toJSON WorkflowJobEvent{Maybe Installation
Text
Organization
User
Repository
WorkflowJob
workflowJobEventWorkflowJob :: WorkflowJob
workflowJobEventAction :: Text
workflowJobEventSender :: User
workflowJobEventRepository :: Repository
workflowJobEventOrganization :: Organization
workflowJobEventInstallation :: Maybe Installation
workflowJobEventWorkflowJob :: WorkflowJobEvent -> WorkflowJob
workflowJobEventAction :: WorkflowJobEvent -> Text
workflowJobEventSender :: WorkflowJobEvent -> User
workflowJobEventRepository :: WorkflowJobEvent -> Repository
workflowJobEventOrganization :: WorkflowJobEvent -> Organization
workflowJobEventInstallation :: WorkflowJobEvent -> Maybe Installation
..} = [Pair] -> Value
object
        [ Key
"installation" Key -> Maybe Installation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Installation
workflowJobEventInstallation
        , Key
"organization" Key -> Organization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Organization
workflowJobEventOrganization
        , Key
"repository"   Key -> Repository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Repository
workflowJobEventRepository
        , Key
"sender"       Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
workflowJobEventSender

        , Key
"action"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
workflowJobEventAction
        , Key
"workflow_job" Key -> WorkflowJob -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= WorkflowJob
workflowJobEventWorkflowJob
        ]


instance Arbitrary WorkflowJobEvent where
    arbitrary :: Gen WorkflowJobEvent
arbitrary = Maybe Installation
-> Organization
-> Repository
-> User
-> Text
-> WorkflowJob
-> WorkflowJobEvent
WorkflowJobEvent
        (Maybe Installation
 -> Organization
 -> Repository
 -> User
 -> Text
 -> WorkflowJob
 -> WorkflowJobEvent)
-> Gen (Maybe Installation)
-> Gen
     (Organization
      -> Repository -> User -> Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Gen Organization
-> Gen
     (Repository -> User -> Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Gen Repository
-> Gen (User -> Text -> WorkflowJob -> WorkflowJobEvent)
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 -> WorkflowJob -> WorkflowJobEvent)
-> Gen User -> Gen (Text -> WorkflowJob -> WorkflowJobEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen User
forall a. Arbitrary a => Gen a
arbitrary

        Gen (Text -> WorkflowJob -> WorkflowJobEvent)
-> Gen Text -> Gen (WorkflowJob -> WorkflowJobEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen (WorkflowJob -> WorkflowJobEvent)
-> Gen WorkflowJob -> Gen WorkflowJobEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen WorkflowJob
forall a. Arbitrary a => Gen a
arbitrary