{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Events.IssuesEvent 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 IssuesEvent = IssuesEvent
    { IssuesEvent -> Maybe Installation
issuesEventInstallation :: Maybe Installation
    , IssuesEvent -> Organization
issuesEventOrganization :: Organization
    , IssuesEvent -> Repository
issuesEventRepository   :: Repository
    , IssuesEvent -> User
issuesEventSender       :: User

    , IssuesEvent -> Text
issuesEventAction       :: Text
    , IssuesEvent -> Maybe User
issuesEventAssignee     :: Maybe User
    , IssuesEvent -> Maybe Changes
issuesEventChanges      :: Maybe Changes
    , IssuesEvent -> Issue
issuesEventIssue        :: Issue
    , IssuesEvent -> Maybe Label
issuesEventLabel        :: Maybe Label
    , IssuesEvent -> Maybe Milestone
issuesEventMilestone    :: Maybe Milestone
    } deriving (IssuesEvent -> IssuesEvent -> Bool
(IssuesEvent -> IssuesEvent -> Bool)
-> (IssuesEvent -> IssuesEvent -> Bool) -> Eq IssuesEvent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: IssuesEvent -> IssuesEvent -> Bool
$c/= :: IssuesEvent -> IssuesEvent -> Bool
== :: IssuesEvent -> IssuesEvent -> Bool
$c== :: IssuesEvent -> IssuesEvent -> Bool
Eq, Int -> IssuesEvent -> ShowS
[IssuesEvent] -> ShowS
IssuesEvent -> String
(Int -> IssuesEvent -> ShowS)
-> (IssuesEvent -> String)
-> ([IssuesEvent] -> ShowS)
-> Show IssuesEvent
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [IssuesEvent] -> ShowS
$cshowList :: [IssuesEvent] -> ShowS
show :: IssuesEvent -> String
$cshow :: IssuesEvent -> String
showsPrec :: Int -> IssuesEvent -> ShowS
$cshowsPrec :: Int -> IssuesEvent -> ShowS
Show, ReadPrec [IssuesEvent]
ReadPrec IssuesEvent
Int -> ReadS IssuesEvent
ReadS [IssuesEvent]
(Int -> ReadS IssuesEvent)
-> ReadS [IssuesEvent]
-> ReadPrec IssuesEvent
-> ReadPrec [IssuesEvent]
-> Read IssuesEvent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [IssuesEvent]
$creadListPrec :: ReadPrec [IssuesEvent]
readPrec :: ReadPrec IssuesEvent
$creadPrec :: ReadPrec IssuesEvent
readList :: ReadS [IssuesEvent]
$creadList :: ReadS [IssuesEvent]
readsPrec :: Int -> ReadS IssuesEvent
$creadsPrec :: Int -> ReadS IssuesEvent
Read)

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

instance FromJSON IssuesEvent where
    parseJSON :: Value -> Parser IssuesEvent
parseJSON (Object Object
x) = Maybe Installation
-> Organization
-> Repository
-> User
-> Text
-> Maybe User
-> Maybe Changes
-> Issue
-> Maybe Label
-> Maybe Milestone
-> IssuesEvent
IssuesEvent
        (Maybe Installation
 -> Organization
 -> Repository
 -> User
 -> Text
 -> Maybe User
 -> Maybe Changes
 -> Issue
 -> Maybe Label
 -> Maybe Milestone
 -> IssuesEvent)
-> Parser (Maybe Installation)
-> Parser
     (Organization
      -> Repository
      -> User
      -> Text
      -> Maybe User
      -> Maybe Changes
      -> Issue
      -> Maybe Label
      -> Maybe Milestone
      -> IssuesEvent)
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 User
   -> Maybe Changes
   -> Issue
   -> Maybe Label
   -> Maybe Milestone
   -> IssuesEvent)
-> Parser Organization
-> Parser
     (Repository
      -> User
      -> Text
      -> Maybe User
      -> Maybe Changes
      -> Issue
      -> Maybe Label
      -> Maybe Milestone
      -> IssuesEvent)
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 User
   -> Maybe Changes
   -> Issue
   -> Maybe Label
   -> Maybe Milestone
   -> IssuesEvent)
-> Parser Repository
-> Parser
     (User
      -> Text
      -> Maybe User
      -> Maybe Changes
      -> Issue
      -> Maybe Label
      -> Maybe Milestone
      -> IssuesEvent)
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 User
   -> Maybe Changes
   -> Issue
   -> Maybe Label
   -> Maybe Milestone
   -> IssuesEvent)
-> Parser User
-> Parser
     (Text
      -> Maybe User
      -> Maybe Changes
      -> Issue
      -> Maybe Label
      -> Maybe Milestone
      -> IssuesEvent)
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 User
   -> Maybe Changes
   -> Issue
   -> Maybe Label
   -> Maybe Milestone
   -> IssuesEvent)
-> Parser Text
-> Parser
     (Maybe User
      -> Maybe Changes
      -> Issue
      -> Maybe Label
      -> Maybe Milestone
      -> IssuesEvent)
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 User
   -> Maybe Changes
   -> Issue
   -> Maybe Label
   -> Maybe Milestone
   -> IssuesEvent)
-> Parser (Maybe User)
-> Parser
     (Maybe Changes
      -> Issue -> Maybe Label -> Maybe Milestone -> IssuesEvent)
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
"assignee"
        Parser
  (Maybe Changes
   -> Issue -> Maybe Label -> Maybe Milestone -> IssuesEvent)
-> Parser (Maybe Changes)
-> Parser (Issue -> Maybe Label -> Maybe Milestone -> IssuesEvent)
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 (Issue -> Maybe Label -> Maybe Milestone -> IssuesEvent)
-> Parser Issue
-> Parser (Maybe Label -> Maybe Milestone -> IssuesEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser Issue
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"issue"
        Parser (Maybe Label -> Maybe Milestone -> IssuesEvent)
-> Parser (Maybe Label) -> Parser (Maybe Milestone -> IssuesEvent)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe Label)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"label"
        Parser (Maybe Milestone -> IssuesEvent)
-> Parser (Maybe Milestone) -> Parser IssuesEvent
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser (Maybe Milestone)
forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
.:? Key
"milestone"

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

instance ToJSON IssuesEvent where
    toJSON :: IssuesEvent -> Value
toJSON IssuesEvent{Maybe Changes
Maybe Installation
Maybe Label
Maybe User
Maybe Milestone
Text
Organization
User
Issue
Repository
issuesEventMilestone :: Maybe Milestone
issuesEventLabel :: Maybe Label
issuesEventIssue :: Issue
issuesEventChanges :: Maybe Changes
issuesEventAssignee :: Maybe User
issuesEventAction :: Text
issuesEventSender :: User
issuesEventRepository :: Repository
issuesEventOrganization :: Organization
issuesEventInstallation :: Maybe Installation
issuesEventMilestone :: IssuesEvent -> Maybe Milestone
issuesEventLabel :: IssuesEvent -> Maybe Label
issuesEventIssue :: IssuesEvent -> Issue
issuesEventChanges :: IssuesEvent -> Maybe Changes
issuesEventAssignee :: IssuesEvent -> Maybe User
issuesEventAction :: IssuesEvent -> Text
issuesEventSender :: IssuesEvent -> User
issuesEventRepository :: IssuesEvent -> Repository
issuesEventOrganization :: IssuesEvent -> Organization
issuesEventInstallation :: IssuesEvent -> Maybe Installation
..} = [Pair] -> Value
object
        [ Key
"installation" Key -> Maybe Installation -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Installation
issuesEventInstallation
        , Key
"organization" Key -> Organization -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Organization
issuesEventOrganization
        , Key
"repository"   Key -> Repository -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Repository
issuesEventRepository
        , Key
"sender"       Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
issuesEventSender

        , Key
"action"       Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
issuesEventAction
        , Key
"assignee"     Key -> Maybe User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe User
issuesEventAssignee
        , Key
"changes"      Key -> Maybe Changes -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Changes
issuesEventChanges
        , Key
"issue"        Key -> Issue -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Issue
issuesEventIssue
        , Key
"label"        Key -> Maybe Label -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Label
issuesEventLabel
        , Key
"milestone"    Key -> Maybe Milestone -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe Milestone
issuesEventMilestone
        ]


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