{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Events.DeleteEvent 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 DeleteEvent = DeleteEvent
    { DeleteEvent -> Maybe Installation
deleteEventInstallation :: Maybe Installation
    , DeleteEvent -> Organization
deleteEventOrganization :: Organization
    , DeleteEvent -> Repository
deleteEventRepository   :: Repository
    , DeleteEvent -> User
deleteEventSender       :: User

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

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

instance FromJSON DeleteEvent where
    parseJSON :: Value -> Parser DeleteEvent
parseJSON (Object Object
x) = Maybe Installation
-> Organization
-> Repository
-> User
-> Text
-> Text
-> Text
-> DeleteEvent
DeleteEvent
        (Maybe Installation
 -> Organization
 -> Repository
 -> User
 -> Text
 -> Text
 -> Text
 -> DeleteEvent)
-> Parser (Maybe Installation)
-> Parser
     (Organization
      -> Repository -> User -> Text -> Text -> Text -> DeleteEvent)
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 -> Text -> Text -> DeleteEvent)
-> Parser Organization
-> Parser
     (Repository -> User -> Text -> Text -> Text -> DeleteEvent)
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 -> Text -> Text -> DeleteEvent)
-> Parser Repository
-> Parser (User -> Text -> Text -> Text -> DeleteEvent)
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 -> Text -> Text -> DeleteEvent)
-> Parser User -> Parser (Text -> Text -> Text -> DeleteEvent)
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 -> Text -> Text -> DeleteEvent)
-> Parser Text -> Parser (Text -> Text -> DeleteEvent)
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
"pusher_type"
        Parser (Text -> Text -> DeleteEvent)
-> Parser Text -> Parser (Text -> DeleteEvent)
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
"ref"
        Parser (Text -> DeleteEvent) -> Parser Text -> Parser DeleteEvent
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
"ref_type"

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

instance ToJSON DeleteEvent where
    toJSON :: DeleteEvent -> Value
toJSON DeleteEvent{Maybe Installation
Text
Organization
User
Repository
deleteEventRefType :: Text
deleteEventRef :: Text
deleteEventPusherType :: Text
deleteEventSender :: User
deleteEventRepository :: Repository
deleteEventOrganization :: Organization
deleteEventInstallation :: Maybe Installation
deleteEventRefType :: DeleteEvent -> Text
deleteEventRef :: DeleteEvent -> Text
deleteEventPusherType :: DeleteEvent -> Text
deleteEventSender :: DeleteEvent -> User
deleteEventRepository :: DeleteEvent -> Repository
deleteEventOrganization :: DeleteEvent -> Organization
deleteEventInstallation :: DeleteEvent -> Maybe Installation
..} = [Pair] -> Value
object
        [ Key
"installation" Key -> Maybe Installation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Installation
deleteEventInstallation
        , Key
"organization" Key -> Organization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Organization
deleteEventOrganization
        , Key
"repository"   Key -> Repository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Repository
deleteEventRepository
        , Key
"sender"       Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
deleteEventSender

        , Key
"pusher_type"  Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
deleteEventPusherType
        , Key
"ref"          Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
deleteEventRef
        , Key
"ref_type"     Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
deleteEventRefType
        ]


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

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