{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Events.StarEvent 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 StarEvent = StarEvent
    { StarEvent -> Maybe Installation
starEventInstallation :: Maybe Installation
    , StarEvent -> Organization
starEventOrganization :: Organization
    , StarEvent -> Repository
starEventRepository   :: Repository
    , StarEvent -> User
starEventSender       :: User

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

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

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

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

instance ToJSON StarEvent where
    toJSON :: StarEvent -> Value
toJSON StarEvent{Maybe Installation
Text
Organization
User
Repository
starEventStarredAt :: Text
starEventAction :: Text
starEventSender :: User
starEventRepository :: Repository
starEventOrganization :: Organization
starEventInstallation :: Maybe Installation
starEventStarredAt :: StarEvent -> Text
starEventAction :: StarEvent -> Text
starEventSender :: StarEvent -> User
starEventRepository :: StarEvent -> Repository
starEventOrganization :: StarEvent -> Organization
starEventInstallation :: StarEvent -> Maybe Installation
..} = [Pair] -> Value
object
        [ Key
"installation" Key -> Maybe Installation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Installation
starEventInstallation
        , Key
"organization" Key -> Organization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Organization
starEventOrganization
        , Key
"repository"   Key -> Repository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Repository
starEventRepository
        , Key
"sender"       Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
starEventSender

        , Key
"action"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
starEventAction
        , Key
"starred_at"   Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
starEventStarredAt
        ]


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