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

------------------------------------------------------------------------------
-- Membership

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


instance FromJSON Membership where
    parseJSON :: Value -> Parser Membership
parseJSON (Object Object
x) = Text -> Text -> Text -> Text -> User -> Membership
Membership
        (Text -> Text -> Text -> Text -> User -> Membership)
-> Parser Text
-> Parser (Text -> Text -> Text -> User -> Membership)
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
"organization_url"
        Parser (Text -> Text -> Text -> User -> Membership)
-> Parser Text -> Parser (Text -> Text -> User -> Membership)
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
"role"
        Parser (Text -> Text -> User -> Membership)
-> Parser Text -> Parser (Text -> User -> Membership)
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
"state"
        Parser (Text -> User -> Membership)
-> Parser Text -> Parser (User -> Membership)
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"
        Parser (User -> Membership) -> Parser User -> Parser Membership
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
"user"

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


instance ToJSON Membership where
    toJSON :: Membership -> Value
toJSON Membership{Text
User
membershipUser :: User
membershipUrl :: Text
membershipState :: Text
membershipRole :: Text
membershipOrganizationUrl :: Text
membershipUser :: Membership -> User
membershipUrl :: Membership -> Text
membershipState :: Membership -> Text
membershipRole :: Membership -> Text
membershipOrganizationUrl :: Membership -> Text
..} = [Pair] -> Value
object
        [ Key
"organization_url" Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
membershipOrganizationUrl
        , Key
"role"             Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
membershipRole
        , Key
"state"            Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
membershipState
        , Key
"url"              Key -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= Text
membershipUrl
        , Key
"user"             Key -> User -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
.= User
membershipUser
        ]


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