{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}
{-# LANGUAGE StrictData        #-}
module GitHub.Types.Base.CommitRef where

import           Data.Aeson                (FromJSON (..), ToJSON (..), object)
import           Data.Aeson.Types          (Value (..), (.:), (.=))
import           Data.Text                 (Text)
import           Data.Text.Arbitrary       ()
import           Test.QuickCheck.Arbitrary (Arbitrary (..))

------------------------------------------------------------------------------
-- CommitRef

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


instance FromJSON CommitRef where
    parseJSON :: Value -> Parser CommitRef
parseJSON (Object Object
x) = Text -> Text -> CommitRef
CommitRef
        (Text -> Text -> CommitRef)
-> Parser Text -> Parser (Text -> CommitRef)
forall (f :: * -> *) a b. Functor 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 -> CommitRef) -> Parser Text -> Parser CommitRef
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 CommitRef
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"CommitRef"


instance ToJSON CommitRef where
    toJSON :: CommitRef -> Value
toJSON CommitRef{Text
commitRefUrl :: Text
commitRefSha :: Text
commitRefUrl :: CommitRef -> Text
commitRefSha :: CommitRef -> Text
..} = [Pair] -> Value
object
        [ Key
"sha" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
commitRefSha
        , Key
"url" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
commitRefUrl
        ]


instance Arbitrary CommitRef where
    arbitrary :: Gen CommitRef
arbitrary = Text -> Text -> CommitRef
CommitRef
        (Text -> Text -> CommitRef) -> Gen Text -> Gen (Text -> CommitRef)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
forall a. Arbitrary a => Gen a
arbitrary
        Gen (Text -> CommitRef) -> Gen Text -> Gen CommitRef
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Gen Text
forall a. Arbitrary a => Gen a
arbitrary