{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wno-unused-imports #-}
{-# OPTIONS_GHC -Wno-dodgy-exports #-}
{-# OPTIONS_GHC -Wno-unused-matches #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Capnp.Gen.Echo where
import qualified Capnp.Message as Message
import qualified Capnp.Untyped as Untyped
import qualified Capnp.Basics as Basics
import qualified Capnp.GenHelpers as GenHelpers
import qualified Capnp.Classes as Classes
import qualified GHC.Generics as Generics
import qualified Capnp.Bits as Std_
import qualified Data.Maybe as Std_
import qualified Capnp.GenHelpers.ReExports.Data.ByteString as BS
import qualified Prelude as Std_
import qualified Data.Word as Std_
import qualified Data.Int as Std_
import Prelude ((<$>), (<*>), (>>=))
newtype Echo msg
    = Echo'newtype_ (Std_.Maybe (Untyped.Cap msg))
instance (Classes.FromPtr msg (Echo msg)) where
    fromPtr msg ptr = (Echo'newtype_ <$> (Classes.fromPtr msg ptr))
instance (Classes.ToPtr s (Echo (Message.MutMsg s))) where
    toPtr msg (Echo'newtype_ (Std_.Nothing)) = (Std_.pure Std_.Nothing)
    toPtr msg (Echo'newtype_ (Std_.Just cap)) = (Std_.pure (Std_.Just (Untyped.PtrCap cap)))
newtype Echo'echo'params msg
    = Echo'echo'params'newtype_ (Untyped.Struct msg)
instance (Untyped.TraverseMsg Echo'echo'params) where
    tMsg f (Echo'echo'params'newtype_ s) = (Echo'echo'params'newtype_ <$> (Untyped.tMsg f s))
instance (Classes.FromStruct msg (Echo'echo'params msg)) where
    fromStruct struct = (Std_.pure (Echo'echo'params'newtype_ struct))
instance (Classes.ToStruct msg (Echo'echo'params msg)) where
    toStruct (Echo'echo'params'newtype_ struct) = struct
instance (Untyped.HasMessage (Echo'echo'params msg)) where
    type InMessage (Echo'echo'params msg) = msg
    message (Echo'echo'params'newtype_ struct) = (Untyped.message struct)
instance (Untyped.MessageDefault (Echo'echo'params msg)) where
    messageDefault msg = (Echo'echo'params'newtype_ (Untyped.messageDefault msg))
instance (Classes.FromPtr msg (Echo'echo'params msg)) where
    fromPtr msg ptr = (Echo'echo'params'newtype_ <$> (Classes.fromPtr msg ptr))
instance (Classes.ToPtr s (Echo'echo'params (Message.MutMsg s))) where
    toPtr msg (Echo'echo'params'newtype_ struct) = (Classes.toPtr msg struct)
instance (Classes.Allocate s (Echo'echo'params (Message.MutMsg s))) where
    new msg = (Echo'echo'params'newtype_ <$> (Untyped.allocStruct msg 0 1))
instance (Basics.ListElem msg (Echo'echo'params msg)) where
    newtype List msg (Echo'echo'params msg)
        = Echo'echo'params'List_ (Untyped.ListOf msg (Untyped.Struct msg))
    listFromPtr msg ptr = (Echo'echo'params'List_ <$> (Classes.fromPtr msg ptr))
    toUntypedList (Echo'echo'params'List_ l) = (Untyped.ListStruct l)
    length (Echo'echo'params'List_ l) = (Untyped.length l)
    index i (Echo'echo'params'List_ l) = (do
        elt <- (Untyped.index i l)
        (Classes.fromStruct elt)
        )
instance (Basics.MutListElem s (Echo'echo'params (Message.MutMsg s))) where
    setIndex (Echo'echo'params'newtype_ elt) i (Echo'echo'params'List_ l) = (Untyped.setIndex elt i l)
    newList msg len = (Echo'echo'params'List_ <$> (Untyped.allocCompositeList msg 0 1 len))
get_Echo'echo'params'query :: ((Untyped.ReadCtx m msg)) => (Echo'echo'params msg) -> (m (Basics.Text msg))
get_Echo'echo'params'query (Echo'echo'params'newtype_ struct) = (do
    ptr <- (Untyped.getPtr 0 struct)
    (Classes.fromPtr (Untyped.message struct) ptr)
    )
set_Echo'echo'params'query :: ((Untyped.RWCtx m s)) => (Echo'echo'params (Message.MutMsg s)) -> (Basics.Text (Message.MutMsg s)) -> (m ())
set_Echo'echo'params'query (Echo'echo'params'newtype_ struct) value = (do
    ptr <- (Classes.toPtr (Untyped.message struct) value)
    (Untyped.setPtr ptr 0 struct)
    )
has_Echo'echo'params'query :: ((Untyped.ReadCtx m msg)) => (Echo'echo'params msg) -> (m Std_.Bool)
has_Echo'echo'params'query (Echo'echo'params'newtype_ struct) = (Std_.isJust <$> (Untyped.getPtr 0 struct))
new_Echo'echo'params'query :: ((Untyped.RWCtx m s)) => Std_.Int -> (Echo'echo'params (Message.MutMsg s)) -> (m (Basics.Text (Message.MutMsg s)))
new_Echo'echo'params'query len struct = (do
    result <- (Basics.newText (Untyped.message struct) len)
    (set_Echo'echo'params'query struct result)
    (Std_.pure result)
    )
newtype Echo'echo'results msg
    = Echo'echo'results'newtype_ (Untyped.Struct msg)
instance (Untyped.TraverseMsg Echo'echo'results) where
    tMsg f (Echo'echo'results'newtype_ s) = (Echo'echo'results'newtype_ <$> (Untyped.tMsg f s))
instance (Classes.FromStruct msg (Echo'echo'results msg)) where
    fromStruct struct = (Std_.pure (Echo'echo'results'newtype_ struct))
instance (Classes.ToStruct msg (Echo'echo'results msg)) where
    toStruct (Echo'echo'results'newtype_ struct) = struct
instance (Untyped.HasMessage (Echo'echo'results msg)) where
    type InMessage (Echo'echo'results msg) = msg
    message (Echo'echo'results'newtype_ struct) = (Untyped.message struct)
instance (Untyped.MessageDefault (Echo'echo'results msg)) where
    messageDefault msg = (Echo'echo'results'newtype_ (Untyped.messageDefault msg))
instance (Classes.FromPtr msg (Echo'echo'results msg)) where
    fromPtr msg ptr = (Echo'echo'results'newtype_ <$> (Classes.fromPtr msg ptr))
instance (Classes.ToPtr s (Echo'echo'results (Message.MutMsg s))) where
    toPtr msg (Echo'echo'results'newtype_ struct) = (Classes.toPtr msg struct)
instance (Classes.Allocate s (Echo'echo'results (Message.MutMsg s))) where
    new msg = (Echo'echo'results'newtype_ <$> (Untyped.allocStruct msg 0 1))
instance (Basics.ListElem msg (Echo'echo'results msg)) where
    newtype List msg (Echo'echo'results msg)
        = Echo'echo'results'List_ (Untyped.ListOf msg (Untyped.Struct msg))
    listFromPtr msg ptr = (Echo'echo'results'List_ <$> (Classes.fromPtr msg ptr))
    toUntypedList (Echo'echo'results'List_ l) = (Untyped.ListStruct l)
    length (Echo'echo'results'List_ l) = (Untyped.length l)
    index i (Echo'echo'results'List_ l) = (do
        elt <- (Untyped.index i l)
        (Classes.fromStruct elt)
        )
instance (Basics.MutListElem s (Echo'echo'results (Message.MutMsg s))) where
    setIndex (Echo'echo'results'newtype_ elt) i (Echo'echo'results'List_ l) = (Untyped.setIndex elt i l)
    newList msg len = (Echo'echo'results'List_ <$> (Untyped.allocCompositeList msg 0 1 len))
get_Echo'echo'results'reply :: ((Untyped.ReadCtx m msg)) => (Echo'echo'results msg) -> (m (Basics.Text msg))
get_Echo'echo'results'reply (Echo'echo'results'newtype_ struct) = (do
    ptr <- (Untyped.getPtr 0 struct)
    (Classes.fromPtr (Untyped.message struct) ptr)
    )
set_Echo'echo'results'reply :: ((Untyped.RWCtx m s)) => (Echo'echo'results (Message.MutMsg s)) -> (Basics.Text (Message.MutMsg s)) -> (m ())
set_Echo'echo'results'reply (Echo'echo'results'newtype_ struct) value = (do
    ptr <- (Classes.toPtr (Untyped.message struct) value)
    (Untyped.setPtr ptr 0 struct)
    )
has_Echo'echo'results'reply :: ((Untyped.ReadCtx m msg)) => (Echo'echo'results msg) -> (m Std_.Bool)
has_Echo'echo'results'reply (Echo'echo'results'newtype_ struct) = (Std_.isJust <$> (Untyped.getPtr 0 struct))
new_Echo'echo'results'reply :: ((Untyped.RWCtx m s)) => Std_.Int -> (Echo'echo'results (Message.MutMsg s)) -> (m (Basics.Text (Message.MutMsg s)))
new_Echo'echo'results'reply len struct = (do
    result <- (Basics.newText (Untyped.message struct) len)
    (set_Echo'echo'results'reply struct result)
    (Std_.pure result)
    )