{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Events.OrganizationEvent 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 OrganizationEvent = OrganizationEvent
    { OrganizationEvent -> Maybe Installation
organizationEventInstallation :: Maybe Installation
    , OrganizationEvent -> Organization
organizationEventOrganization :: Organization
    , OrganizationEvent -> User
organizationEventSender       :: User

    , OrganizationEvent -> Text
organizationEventAction       :: Text
    , OrganizationEvent -> Maybe Invitation
organizationEventInvitation   :: Maybe Invitation
    , OrganizationEvent -> Maybe Membership
organizationEventMembership   :: Maybe Membership
    , OrganizationEvent -> Maybe User
organizationEventUser         :: Maybe User
    } deriving (OrganizationEvent -> OrganizationEvent -> Bool
(OrganizationEvent -> OrganizationEvent -> Bool)
-> (OrganizationEvent -> OrganizationEvent -> Bool)
-> Eq OrganizationEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OrganizationEvent -> OrganizationEvent -> Bool
$c/= :: OrganizationEvent -> OrganizationEvent -> Bool
== :: OrganizationEvent -> OrganizationEvent -> Bool
$c== :: OrganizationEvent -> OrganizationEvent -> Bool
Eq, Int -> OrganizationEvent -> ShowS
[OrganizationEvent] -> ShowS
OrganizationEvent -> String
(Int -> OrganizationEvent -> ShowS)
-> (OrganizationEvent -> String)
-> ([OrganizationEvent] -> ShowS)
-> Show OrganizationEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OrganizationEvent] -> ShowS
$cshowList :: [OrganizationEvent] -> ShowS
show :: OrganizationEvent -> String
$cshow :: OrganizationEvent -> String
showsPrec :: Int -> OrganizationEvent -> ShowS
$cshowsPrec :: Int -> OrganizationEvent -> ShowS
Show, ReadPrec [OrganizationEvent]
ReadPrec OrganizationEvent
Int -> ReadS OrganizationEvent
ReadS [OrganizationEvent]
(Int -> ReadS OrganizationEvent)
-> ReadS [OrganizationEvent]
-> ReadPrec OrganizationEvent
-> ReadPrec [OrganizationEvent]
-> Read OrganizationEvent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [OrganizationEvent]
$creadListPrec :: ReadPrec [OrganizationEvent]
readPrec :: ReadPrec OrganizationEvent
$creadPrec :: ReadPrec OrganizationEvent
readList :: ReadS [OrganizationEvent]
$creadList :: ReadS [OrganizationEvent]
readsPrec :: Int -> ReadS OrganizationEvent
$creadsPrec :: Int -> ReadS OrganizationEvent
Read)

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

instance FromJSON OrganizationEvent where
    parseJSON :: Value -> Parser OrganizationEvent
parseJSON (Object Object
x) = Maybe Installation
-> Organization
-> User
-> Text
-> Maybe Invitation
-> Maybe Membership
-> Maybe User
-> OrganizationEvent
OrganizationEvent
        (Maybe Installation
 -> Organization
 -> User
 -> Text
 -> Maybe Invitation
 -> Maybe Membership
 -> Maybe User
 -> OrganizationEvent)
-> Parser (Maybe Installation)
-> Parser
     (Organization
      -> User
      -> Text
      -> Maybe Invitation
      -> Maybe Membership
      -> Maybe User
      -> OrganizationEvent)
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
   -> User
   -> Text
   -> Maybe Invitation
   -> Maybe Membership
   -> Maybe User
   -> OrganizationEvent)
-> Parser Organization
-> Parser
     (User
      -> Text
      -> Maybe Invitation
      -> Maybe Membership
      -> Maybe User
      -> OrganizationEvent)
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
  (User
   -> Text
   -> Maybe Invitation
   -> Maybe Membership
   -> Maybe User
   -> OrganizationEvent)
-> Parser User
-> Parser
     (Text
      -> Maybe Invitation
      -> Maybe Membership
      -> Maybe User
      -> OrganizationEvent)
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 Invitation
   -> Maybe Membership
   -> Maybe User
   -> OrganizationEvent)
-> Parser Text
-> Parser
     (Maybe Invitation
      -> Maybe Membership -> Maybe User -> OrganizationEvent)
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 Invitation
   -> Maybe Membership -> Maybe User -> OrganizationEvent)
-> Parser (Maybe Invitation)
-> Parser (Maybe Membership -> Maybe User -> OrganizationEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe Invitation)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"invitation"
        Parser (Maybe Membership -> Maybe User -> OrganizationEvent)
-> Parser (Maybe Membership)
-> Parser (Maybe User -> OrganizationEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe Membership)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"membership"
        Parser (Maybe User -> OrganizationEvent)
-> Parser (Maybe User) -> Parser OrganizationEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe User)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"user"

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

instance ToJSON OrganizationEvent where
    toJSON :: OrganizationEvent -> Value
toJSON OrganizationEvent{Maybe Installation
Maybe Invitation
Maybe User
Maybe Membership
Text
Organization
User
organizationEventUser :: Maybe User
organizationEventMembership :: Maybe Membership
organizationEventInvitation :: Maybe Invitation
organizationEventAction :: Text
organizationEventSender :: User
organizationEventOrganization :: Organization
organizationEventInstallation :: Maybe Installation
organizationEventUser :: OrganizationEvent -> Maybe User
organizationEventMembership :: OrganizationEvent -> Maybe Membership
organizationEventInvitation :: OrganizationEvent -> Maybe Invitation
organizationEventAction :: OrganizationEvent -> Text
organizationEventSender :: OrganizationEvent -> User
organizationEventOrganization :: OrganizationEvent -> Organization
organizationEventInstallation :: OrganizationEvent -> Maybe Installation
..} = [Pair] -> Value
object
        [ Key
"installation" Key -> Maybe Installation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Installation
organizationEventInstallation
        , Key
"organization" Key -> Organization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Organization
organizationEventOrganization
        , Key
"sender"       Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
organizationEventSender

        , Key
"action"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
organizationEventAction
        , Key
"invitation"   Key -> Maybe Invitation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Invitation
organizationEventInvitation
        , Key
"membership"   Key -> Maybe Membership -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Membership
organizationEventMembership
        , Key
"user"         Key -> Maybe User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe User
organizationEventUser
        ]


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