{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Base.StatusCommit 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.CommitDetails
import           GitHub.Types.Base.CommitRefHtml
import           GitHub.Types.Base.User

------------------------------------------------------------------------------
-- StatusCommit

data StatusCommit = StatusCommit
    { StatusCommit -> Maybe User
statusCommitAuthor      :: Maybe User
    , StatusCommit -> Text
statusCommitCommentsUrl :: Text
    , StatusCommit -> CommitDetails
statusCommitCommit      :: CommitDetails
    , StatusCommit -> Maybe User
statusCommitCommitter   :: Maybe User
    , StatusCommit -> Text
statusCommitHtmlUrl     :: Text
    , StatusCommit -> Text
statusCommitNodeId      :: Text
    , StatusCommit -> [CommitRefHtml]
statusCommitParents     :: [CommitRefHtml]
    , StatusCommit -> Text
statusCommitSha         :: Text
    , StatusCommit -> Text
statusCommitUrl         :: Text
    } deriving (StatusCommit -> StatusCommit -> Bool
(StatusCommit -> StatusCommit -> Bool)
-> (StatusCommit -> StatusCommit -> Bool) -> Eq StatusCommit
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: StatusCommit -> StatusCommit -> Bool
$c/= :: StatusCommit -> StatusCommit -> Bool
== :: StatusCommit -> StatusCommit -> Bool
$c== :: StatusCommit -> StatusCommit -> Bool
Eq, Int -> StatusCommit -> ShowS
[StatusCommit] -> ShowS
StatusCommit -> String
(Int -> StatusCommit -> ShowS)
-> (StatusCommit -> String)
-> ([StatusCommit] -> ShowS)
-> Show StatusCommit
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StatusCommit] -> ShowS
$cshowList :: [StatusCommit] -> ShowS
show :: StatusCommit -> String
$cshow :: StatusCommit -> String
showsPrec :: Int -> StatusCommit -> ShowS
$cshowsPrec :: Int -> StatusCommit -> ShowS
Show, ReadPrec [StatusCommit]
ReadPrec StatusCommit
Int -> ReadS StatusCommit
ReadS [StatusCommit]
(Int -> ReadS StatusCommit)
-> ReadS [StatusCommit]
-> ReadPrec StatusCommit
-> ReadPrec [StatusCommit]
-> Read StatusCommit
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [StatusCommit]
$creadListPrec :: ReadPrec [StatusCommit]
readPrec :: ReadPrec StatusCommit
$creadPrec :: ReadPrec StatusCommit
readList :: ReadS [StatusCommit]
$creadList :: ReadS [StatusCommit]
readsPrec :: Int -> ReadS StatusCommit
$creadsPrec :: Int -> ReadS StatusCommit
Read)


instance FromJSON StatusCommit where
    parseJSON :: Value -> Parser StatusCommit
parseJSON (Object Object
x) = Maybe User
-> Text
-> CommitDetails
-> Maybe User
-> Text
-> Text
-> [CommitRefHtml]
-> Text
-> Text
-> StatusCommit
StatusCommit
        (Maybe User
 -> Text
 -> CommitDetails
 -> Maybe User
 -> Text
 -> Text
 -> [CommitRefHtml]
 -> Text
 -> Text
 -> StatusCommit)
-> Parser (Maybe User)
-> Parser
     (Text
      -> CommitDetails
      -> Maybe User
      -> Text
      -> Text
      -> [CommitRefHtml]
      -> Text
      -> Text
      -> StatusCommit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
x Object -> Key -> Parser (Maybe User)
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"author"
        Parser
  (Text
   -> CommitDetails
   -> Maybe User
   -> Text
   -> Text
   -> [CommitRefHtml]
   -> Text
   -> Text
   -> StatusCommit)
-> Parser Text
-> Parser
     (CommitDetails
      -> Maybe User
      -> Text
      -> Text
      -> [CommitRefHtml]
      -> Text
      -> Text
      -> StatusCommit)
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
"comments_url"
        Parser
  (CommitDetails
   -> Maybe User
   -> Text
   -> Text
   -> [CommitRefHtml]
   -> Text
   -> Text
   -> StatusCommit)
-> Parser CommitDetails
-> Parser
     (Maybe User
      -> Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser CommitDetails
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"commit"
        Parser
  (Maybe User
   -> Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Parser (Maybe User)
-> Parser
     (Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
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 a
.: Key
"committer"
        Parser
  (Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Parser Text
-> Parser (Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
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
"html_url"
        Parser (Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Parser Text
-> Parser ([CommitRefHtml] -> Text -> Text -> StatusCommit)
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
"node_id"
        Parser ([CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Parser [CommitRefHtml] -> Parser (Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
x Object -> Key -> Parser [CommitRefHtml]
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"parents"
        Parser (Text -> Text -> StatusCommit)
-> Parser Text -> Parser (Text -> StatusCommit)
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
"sha"
        Parser (Text -> StatusCommit) -> Parser Text -> Parser StatusCommit
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
"url"

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


instance ToJSON StatusCommit where
    toJSON :: StatusCommit -> Value
toJSON StatusCommit{[CommitRefHtml]
Maybe User
Text
CommitDetails
statusCommitUrl :: Text
statusCommitSha :: Text
statusCommitParents :: [CommitRefHtml]
statusCommitNodeId :: Text
statusCommitHtmlUrl :: Text
statusCommitCommitter :: Maybe User
statusCommitCommit :: CommitDetails
statusCommitCommentsUrl :: Text
statusCommitAuthor :: Maybe User
statusCommitUrl :: StatusCommit -> Text
statusCommitSha :: StatusCommit -> Text
statusCommitParents :: StatusCommit -> [CommitRefHtml]
statusCommitNodeId :: StatusCommit -> Text
statusCommitHtmlUrl :: StatusCommit -> Text
statusCommitCommitter :: StatusCommit -> Maybe User
statusCommitCommit :: StatusCommit -> CommitDetails
statusCommitCommentsUrl :: StatusCommit -> Text
statusCommitAuthor :: StatusCommit -> Maybe User
..} = [Pair] -> Value
object
        [ Key
"author"       Key -> Maybe User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe User
statusCommitAuthor
        , Key
"comments_url" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
statusCommitCommentsUrl
        , Key
"commit"       Key -> CommitDetails -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= CommitDetails
statusCommitCommit
        , Key
"committer"    Key -> Maybe User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Maybe User
statusCommitCommitter
        , Key
"html_url"     Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
statusCommitHtmlUrl
        , Key
"node_id"      Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
statusCommitNodeId
        , Key
"parents"      Key -> [CommitRefHtml] -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= [CommitRefHtml]
statusCommitParents
        , Key
"sha"          Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
statusCommitSha
        , Key
"url"          Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
statusCommitUrl
        ]


instance Arbitrary StatusCommit where
    arbitrary :: Gen StatusCommit
arbitrary = Maybe User
-> Text
-> CommitDetails
-> Maybe User
-> Text
-> Text
-> [CommitRefHtml]
-> Text
-> Text
-> StatusCommit
StatusCommit
        (Maybe User
 -> Text
 -> CommitDetails
 -> Maybe User
 -> Text
 -> Text
 -> [CommitRefHtml]
 -> Text
 -> Text
 -> StatusCommit)
-> Gen (Maybe User)
-> Gen
     (Text
      -> CommitDetails
      -> Maybe User
      -> Text
      -> Text
      -> [CommitRefHtml]
      -> Text
      -> Text
      -> StatusCommit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen (Maybe User)
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (Text
   -> CommitDetails
   -> Maybe User
   -> Text
   -> Text
   -> [CommitRefHtml]
   -> Text
   -> Text
   -> StatusCommit)
-> Gen Text
-> Gen
     (CommitDetails
      -> Maybe User
      -> Text
      -> Text
      -> [CommitRefHtml]
      -> Text
      -> Text
      -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (CommitDetails
   -> Maybe User
   -> Text
   -> Text
   -> [CommitRefHtml]
   -> Text
   -> Text
   -> StatusCommit)
-> Gen CommitDetails
-> Gen
     (Maybe User
      -> Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen CommitDetails
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (Maybe User
   -> Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Gen (Maybe User)
-> Gen
     (Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen (Maybe User)
forall a. Arbitrary a => Gen a
arbitrary
        Gen
  (Text -> Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Gen Text
-> Gen (Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Text -> [CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Gen Text
-> Gen ([CommitRefHtml] -> Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen ([CommitRefHtml] -> Text -> Text -> StatusCommit)
-> Gen [CommitRefHtml] -> Gen (Text -> Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen [CommitRefHtml]
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Text -> Text -> StatusCommit)
-> Gen Text -> Gen (Text -> StatusCommit)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Text -> StatusCommit) -> Gen Text -> Gen StatusCommit
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary