{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData    #-}
module Network.Tox.Types.Events where

import qualified Data.ByteString                      as BS
import           Data.MessagePack                     (MessagePack)
import           Data.Word                            (Word16, Word32, Word64)
import           FFI.Tox.Tox                          (ConferenceType,
                                                       Connection, FileControl,
                                                       GroupExitType,
                                                       GroupJoinFail,
                                                       GroupModEvent,
                                                       GroupPrivacyState,
                                                       GroupTopicLock,
                                                       GroupVoiceState,
                                                       MessageType, UserStatus)
import           GHC.Generics                         (Generic)
import           Network.Tox.C.Type                   (PublicKey)
import           Test.QuickCheck.Arbitrary            (Arbitrary (..))
import           Test.QuickCheck.Arbitrary.Generic    (genericArbitrary,
                                                       genericShrink)
import           Test.QuickCheck.Instances.ByteString ()


data Event
    = SelfConnectionStatus      { Event -> Connection
connectionStatus :: Connection }

    | FriendRequest             { Event -> PublicKey
publicKey :: PublicKey, Event -> ByteString
message :: BS.ByteString }
    | FriendConnectionStatus    { Event -> Word32
friendNumber :: Word32, connectionStatus :: Connection }
    | FriendLossyPacket         { friendNumber :: Word32, Event -> ByteString
data' :: BS.ByteString }
    | FriendLosslessPacket      { friendNumber :: Word32, data' :: BS.ByteString }

    | FriendName                { friendNumber :: Word32, Event -> ByteString
name :: BS.ByteString }
    | FriendStatus              { friendNumber :: Word32, Event -> UserStatus
status :: UserStatus }
    | FriendStatusMessage       { friendNumber :: Word32, Event -> ByteString
statusMessage :: BS.ByteString }

    | FriendMessage             { friendNumber :: Word32, Event -> MessageType
messageType :: MessageType, message :: BS.ByteString }
    | FriendReadReceipt         { friendNumber :: Word32, Event -> Word32
messageId :: Word32 }
    | FriendTyping              { friendNumber :: Word32, Event -> Bool
typing :: Bool }

    | FileChunkRequest          { friendNumber :: Word32, Event -> Word32
fileNumber :: Word32, Event -> Word64
position :: Word64, Event -> Word16
length :: Word16 }
    | FileRecv                  { friendNumber :: Word32, fileNumber :: Word32, Event -> Word32
kind :: Word32, Event -> Word64
fileSize :: Word64, Event -> ByteString
filename :: BS.ByteString }
    | FileRecvChunk             { friendNumber :: Word32, fileNumber :: Word32, position :: Word64, data' ::  BS.ByteString }
    | FileRecvControl           { friendNumber :: Word32, fileNumber :: Word32, Event -> FileControl
control :: FileControl }

    | ConferenceInvite          { friendNumber :: Word32, Event -> ConferenceType
conferenceType :: ConferenceType, Event -> ByteString
cookie :: BS.ByteString }
    | ConferenceConnected       { Event -> Word32
conferenceNumber :: Word32 }
    | ConferencePeerListChanged { conferenceNumber :: Word32 }
    | ConferencePeerName        { conferenceNumber :: Word32, Event -> Word32
peerNumber :: Word32, name :: BS.ByteString }
    | ConferenceTitle           { conferenceNumber :: Word32, peerNumber :: Word32, Event -> ByteString
title :: BS.ByteString }

    | ConferenceMessage         { conferenceNumber :: Word32, peerNumber :: Word32, messageType :: MessageType, message :: BS.ByteString }

    | GroupPeerName             { Event -> Word32
groupNumber :: Word32, Event -> Word32
peerId :: Word32, name :: BS.ByteString }
    | GroupPeerStatus           { groupNumber :: Word32, peerId :: Word32, status :: UserStatus }
    | GroupTopic                { groupNumber :: Word32, peerId :: Word32, Event -> ByteString
topic :: BS.ByteString }
    | GroupPrivacyState         { groupNumber :: Word32, Event -> GroupPrivacyState
privacyState :: GroupPrivacyState }
    | GroupVoiceState           { groupNumber :: Word32, Event -> GroupVoiceState
voiceState :: GroupVoiceState }
    | GroupTopicLock            { groupNumber :: Word32, Event -> GroupTopicLock
topicLock :: GroupTopicLock }
    | GroupPeerLimit            { groupNumber :: Word32, Event -> Word32
peerLimit :: Word32 }
    | GroupPassword             { groupNumber :: Word32, Event -> ByteString
password :: BS.ByteString }
    | GroupMessage              { groupNumber :: Word32, peerId :: Word32, messageType :: MessageType, message :: BS.ByteString, messageId :: Word32 }
    | GroupPrivateMessage       { groupNumber :: Word32, peerId :: Word32, messageType :: MessageType, message :: BS.ByteString }
    | GroupCustomPacket         { groupNumber :: Word32, peerId :: Word32, data' :: BS.ByteString }
    | GroupCustomPrivatePacket  { groupNumber :: Word32, peerId :: Word32, data' :: BS.ByteString }
    | GroupInvite               { groupNumber :: Word32, Event -> ByteString
inviteData :: BS.ByteString, Event -> ByteString
groupName :: BS.ByteString }
    | GroupPeerJoin             { groupNumber :: Word32, peerId :: Word32 }
    | GroupPeerExit             { groupNumber :: Word32, peerId :: Word32, Event -> GroupExitType
exitType :: GroupExitType, name :: BS.ByteString, Event -> ByteString
partMessage :: BS.ByteString }
    | GroupSelfJoin             { groupNumber :: Word32 }
    | GroupJoinFail             { groupNumber :: Word32, Event -> GroupJoinFail
failType :: GroupJoinFail }
    | GroupModeration           { groupNumber :: Word32, Event -> Word32
sourcePeerId :: Word32, Event -> Word32
targetPeerId :: Word32, Event -> GroupModEvent
modType :: GroupModEvent }

    | DhtGetNodesResponse       { publicKey :: PublicKey, Event -> ByteString
ip :: BS.ByteString, Event -> Word16
port :: Word16 }
    deriving (Eq Event
Eq Event
-> (Event -> Event -> Ordering)
-> (Event -> Event -> Bool)
-> (Event -> Event -> Bool)
-> (Event -> Event -> Bool)
-> (Event -> Event -> Bool)
-> (Event -> Event -> Event)
-> (Event -> Event -> Event)
-> Ord Event
Event -> Event -> Bool
Event -> Event -> Ordering
Event -> Event -> Event
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Event -> Event -> Event
$cmin :: Event -> Event -> Event
max :: Event -> Event -> Event
$cmax :: Event -> Event -> Event
>= :: Event -> Event -> Bool
$c>= :: Event -> Event -> Bool
> :: Event -> Event -> Bool
$c> :: Event -> Event -> Bool
<= :: Event -> Event -> Bool
$c<= :: Event -> Event -> Bool
< :: Event -> Event -> Bool
$c< :: Event -> Event -> Bool
compare :: Event -> Event -> Ordering
$ccompare :: Event -> Event -> Ordering
$cp1Ord :: Eq Event
Ord, Event -> Event -> Bool
(Event -> Event -> Bool) -> (Event -> Event -> Bool) -> Eq Event
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Event -> Event -> Bool
$c/= :: Event -> Event -> Bool
== :: Event -> Event -> Bool
$c== :: Event -> Event -> Bool
Eq, Int -> Event -> ShowS
[Event] -> ShowS
Event -> String
(Int -> Event -> ShowS)
-> (Event -> String) -> ([Event] -> ShowS) -> Show Event
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Event] -> ShowS
$cshowList :: [Event] -> ShowS
show :: Event -> String
$cshow :: Event -> String
showsPrec :: Int -> Event -> ShowS
$cshowsPrec :: Int -> Event -> ShowS
Show, (forall x. Event -> Rep Event x)
-> (forall x. Rep Event x -> Event) -> Generic Event
forall x. Rep Event x -> Event
forall x. Event -> Rep Event x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Event x -> Event
$cfrom :: forall x. Event -> Rep Event x
Generic)

instance MessagePack Event
instance Arbitrary Event where
    arbitrary :: Gen Event
arbitrary = Gen Event
forall a (ga :: * -> *) (some :: Bool).
(Generic a, GArbitrary a ga some, ga ~ Rep a) =>
Gen a
genericArbitrary
    shrink :: Event -> [Event]
shrink = Event -> [Event]
forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink

data Events = Events [Event]
    deriving (Eq Events
Eq Events
-> (Events -> Events -> Ordering)
-> (Events -> Events -> Bool)
-> (Events -> Events -> Bool)
-> (Events -> Events -> Bool)
-> (Events -> Events -> Bool)
-> (Events -> Events -> Events)
-> (Events -> Events -> Events)
-> Ord Events
Events -> Events -> Bool
Events -> Events -> Ordering
Events -> Events -> Events
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Events -> Events -> Events
$cmin :: Events -> Events -> Events
max :: Events -> Events -> Events
$cmax :: Events -> Events -> Events
>= :: Events -> Events -> Bool
$c>= :: Events -> Events -> Bool
> :: Events -> Events -> Bool
$c> :: Events -> Events -> Bool
<= :: Events -> Events -> Bool
$c<= :: Events -> Events -> Bool
< :: Events -> Events -> Bool
$c< :: Events -> Events -> Bool
compare :: Events -> Events -> Ordering
$ccompare :: Events -> Events -> Ordering
$cp1Ord :: Eq Events
Ord, Events -> Events -> Bool
(Events -> Events -> Bool)
-> (Events -> Events -> Bool) -> Eq Events
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Events -> Events -> Bool
$c/= :: Events -> Events -> Bool
== :: Events -> Events -> Bool
$c== :: Events -> Events -> Bool
Eq, Int -> Events -> ShowS
[Events] -> ShowS
Events -> String
(Int -> Events -> ShowS)
-> (Events -> String) -> ([Events] -> ShowS) -> Show Events
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Events] -> ShowS
$cshowList :: [Events] -> ShowS
show :: Events -> String
$cshow :: Events -> String
showsPrec :: Int -> Events -> ShowS
$cshowsPrec :: Int -> Events -> ShowS
Show, (forall x. Events -> Rep Events x)
-> (forall x. Rep Events x -> Events) -> Generic Events
forall x. Rep Events x -> Events
forall x. Events -> Rep Events x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Events x -> Events
$cfrom :: forall x. Events -> Rep Events x
Generic)

instance MessagePack Events
instance Arbitrary Events where
    arbitrary :: Gen Events
arbitrary = Gen Events
forall a (ga :: * -> *) (some :: Bool).
(Generic a, GArbitrary a ga some, ga ~ Rep a) =>
Gen a
genericArbitrary
    shrink :: Events -> [Events]
shrink = Events -> [Events]
forall a.
(Generic a, RecursivelyShrink (Rep a), GSubterms (Rep a) a) =>
a -> [a]
genericShrink