    {-# LANGUAGE TypeApplications #-}

    -- | Copyright  : Will Thompson and Iñaki García Etxebarria
    -- License    : LGPL-2.1
    -- Maintainer : Iñaki García Etxebarria
    --
    -- The t'GI.GLib.Structs.Tuples.Tuples' struct is used to return records (or tuples) from the
    -- t'GI.GLib.Structs.Relation.Relation' by @/g_relation_select()/@. It only contains one public
    -- member - the number of records that matched. To access the matched
    -- records, you must use 'GI.GLib.Structs.Tuples.tuplesIndex'.

    #if !defined(__HADDOCK_VERSION__)
    #define ENABLE_OVERLOADING
    #endif

    module GI.GLib.Structs.Tuples
        (

    -- * Exported types
        Tuples(..)                              ,
        newZeroTuples                           ,

     -- * Methods
    -- |
    --
    --  === __Click to display all available methods, including inherited ones__
    -- ==== Methods
    -- [destroy]("GI.GLib.Structs.Tuples#g:method:destroy"), [index]("GI.GLib.Structs.Tuples#g:method:index").
    --
    -- ==== Getters
    -- /None/.
    --
    -- ==== Setters
    -- /None/.

    #if defined(ENABLE_OVERLOADING)
        ResolveTuplesMethod                     ,
    #endif

    -- ** destroy #method:destroy#

    #if defined(ENABLE_OVERLOADING)
        TuplesDestroyMethodInfo                 ,
    #endif
        tuplesDestroy                           ,

    -- ** index #method:index#

    #if defined(ENABLE_OVERLOADING)
        TuplesIndexMethodInfo                   ,
    #endif
        tuplesIndex                             ,

     -- * Properties

    -- ** len #attr:len#
    -- | the number of records that matched.

        getTuplesLen                            ,
        setTuplesLen                            ,
    #if defined(ENABLE_OVERLOADING)
        tuples_len                              ,
    #endif

        ) where

    import Data.GI.Base.ShortPrelude
    import qualified Data.GI.Base.ShortPrelude as SP
    import qualified Data.GI.Base.Overloading as O
    import qualified Prelude as P

    import qualified Data.GI.Base.Attributes as GI.Attributes
    import qualified Data.GI.Base.BasicTypes as B.Types
    import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
    import qualified Data.GI.Base.GArray as B.GArray
    import qualified Data.GI.Base.GClosure as B.GClosure
    import qualified Data.GI.Base.GError as B.GError
    import qualified Data.GI.Base.GHashTable as B.GHT
    import qualified Data.GI.Base.GVariant as B.GVariant
    import qualified Data.GI.Base.GValue as B.GValue
    import qualified Data.GI.Base.GParamSpec as B.GParamSpec
    import qualified Data.GI.Base.CallStack as B.CallStack
    import qualified Data.GI.Base.Properties as B.Properties
    import qualified Data.GI.Base.Signals as B.Signals
    import qualified Control.Monad.IO.Class as MIO
    import qualified Data.Coerce as Coerce
    import qualified Data.Text as T
    import qualified Data.Kind as DK
    import qualified Data.ByteString.Char8 as B
    import qualified Data.Map as Map
    import qualified Foreign.Ptr as FP
    import qualified GHC.OverloadedLabels as OL
    import qualified GHC.Records as R
    import qualified Data.Word as DW
    import qualified Data.Int as DI
    import qualified System.Posix.Types as SPT
    import qualified Foreign.C.Types as FCT

    -- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
    #if MIN_VERSION_base(4,18,0)

    #else

    #endif

    -- | Memory-managed wrapper type.
    newtype Tuples = Tuples (SP.ManagedPtr Tuples)
        deriving (Tuples -> Tuples -> Bool
    (Tuples -> Tuples -> Bool)
    -> (Tuples -> Tuples -> Bool) -> Eq Tuples
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Tuples -> Tuples -> Bool
    == :: Tuples -> Tuples -> Bool
    $c/= :: Tuples -> Tuples -> Bool
    /= :: Tuples -> Tuples -> Bool
    Eq)

    instance SP.ManagedPtrNewtype Tuples where
        toManagedPtr :: Tuples -> ManagedPtr Tuples
    toManagedPtr (Tuples ManagedPtr Tuples
    p) = ManagedPtr Tuples
    p

    instance BoxedPtr Tuples where
        boxedPtrCopy :: Tuples -> IO Tuples
    boxedPtrCopy = \Tuples
    p -> Tuples -> (Ptr Tuples -> IO Tuples) -> IO Tuples
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    B.ManagedPtr.withManagedPtr Tuples
    p (Int -> Ptr Tuples -> IO (Ptr Tuples)
    forall a. (HasCallStack, CallocPtr a) => Int -> Ptr a -> IO (Ptr a)
    copyBytes Int
    4 (Ptr Tuples -> IO (Ptr Tuples))
    -> (Ptr Tuples -> IO Tuples) -> Ptr Tuples -> IO Tuples
    forall (m :: * -> *) a b c.
    Monad m =>
    (a -> m b) -> (b -> m c) -> a -> m c
    >=> (ManagedPtr Tuples -> Tuples) -> Ptr Tuples -> IO Tuples
    forall a.
    (HasCallStack, BoxedPtr a) =>
    (ManagedPtr a -> a) -> Ptr a -> IO a
    B.ManagedPtr.wrapPtr ManagedPtr Tuples -> Tuples
    Tuples)
        boxedPtrFree :: Tuples -> IO ()
    boxedPtrFree = \Tuples
    x -> Tuples -> (Ptr Tuples -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    SP.withManagedPtr Tuples
    x Ptr Tuples -> IO ()
    forall a. Ptr a -> IO ()
    SP.freeMem
    instance CallocPtr Tuples where
        boxedPtrCalloc :: IO (Ptr Tuples)
    boxedPtrCalloc = Int -> IO (Ptr Tuples)
    forall a. Int -> IO (Ptr a)
    callocBytes Int
    4

    -- | Construct a `Tuples` struct initialized to zero.
    newZeroTuples :: MonadIO m => m Tuples
    newZeroTuples :: forall (m :: * -> *). MonadIO m => m Tuples
    newZeroTuples = IO Tuples -> m Tuples
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Tuples -> m Tuples) -> IO Tuples -> m Tuples
    forall a b. (a -> b) -> a -> b
    $ IO (Ptr Tuples)
    forall a. CallocPtr a => IO (Ptr a)
    boxedPtrCalloc IO (Ptr Tuples) -> (Ptr Tuples -> IO Tuples) -> IO Tuples
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= (ManagedPtr Tuples -> Tuples) -> Ptr Tuples -> IO Tuples
    forall a.
    (HasCallStack, BoxedPtr a) =>
    (ManagedPtr a -> a) -> Ptr a -> IO a
    wrapPtr ManagedPtr Tuples -> Tuples
    Tuples

    instance tag ~ 'AttrSet => Constructible Tuples tag where
        new :: forall (m :: * -> *).
    MonadIO m =>
    (ManagedPtr Tuples -> Tuples) -> [AttrOp Tuples tag] -> m Tuples
    new ManagedPtr Tuples -> Tuples
    _ [AttrOp Tuples tag]
    attrs = do
            Tuples
    o <- m Tuples
    forall (m :: * -> *). MonadIO m => m Tuples
    newZeroTuples
            Tuples -> [AttrOp Tuples 'AttrSet] -> m ()
    forall o (m :: * -> *).
    MonadIO m =>
    o -> [AttrOp o 'AttrSet] -> m ()
    GI.Attributes.set Tuples
    o [AttrOp Tuples tag]
    [AttrOp Tuples 'AttrSet]
    attrs
            Tuples -> m Tuples
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Tuples
    o

    -- | Get the value of the “@len@” field.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.get' tuples #len
    -- @
    getTuplesLen :: MonadIO m => Tuples -> m Word32
    getTuplesLen :: forall (m :: * -> *). MonadIO m => Tuples -> m Word32
    getTuplesLen Tuples
    s = IO Word32 -> m Word32
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO Word32 -> m Word32) -> IO Word32 -> m Word32
    forall a b. (a -> b) -> a -> b
    $ Tuples -> (Ptr Tuples -> IO Word32) -> IO Word32
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr Tuples
    s ((Ptr Tuples -> IO Word32) -> IO Word32)
    -> (Ptr Tuples -> IO Word32) -> IO Word32
    forall a b. (a -> b) -> a -> b
    $ \Ptr Tuples
    ptr -> do
        Word32
    val <- Ptr Word32 -> IO Word32
    forall a. Storable a => Ptr a -> IO a
    peek (Ptr Tuples
    ptr Ptr Tuples -> Int -> Ptr Word32
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` Int
    0) :: IO Word32
        Word32 -> IO Word32
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Word32
    val

    -- | Set the value of the “@len@” field.
    -- When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to
    --
    -- @
    -- 'Data.GI.Base.Attributes.set' tuples [ #len 'Data.GI.Base.Attributes.:=' value ]
    -- @
    setTuplesLen :: MonadIO m => Tuples -> Word32 -> m ()
    setTuplesLen :: forall (m :: * -> *). MonadIO m => Tuples -> Word32 -> m ()
    setTuplesLen Tuples
    s Word32
    val = IO () -> m ()
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> IO () -> m ()
    forall a b. (a -> b) -> a -> b
    $ Tuples -> (Ptr Tuples -> IO ()) -> IO ()
    forall a c.
    (HasCallStack, ManagedPtrNewtype a) =>
    a -> (Ptr a -> IO c) -> IO c
    withManagedPtr Tuples
    s ((Ptr Tuples -> IO ()) -> IO ()) -> (Ptr Tuples -> IO ()) -> IO ()
    forall a b. (a -> b) -> a -> b
    $ \Ptr Tuples
    ptr -> do
        Ptr Word32 -> Word32 -> IO ()
    forall a. Storable a => Ptr a -> a -> IO ()
    poke (Ptr Tuples
    ptr Ptr Tuples -> Int -> Ptr Word32
    forall a b. Ptr a -> Int -> Ptr b
    `plusPtr` Int
    0) (Word32
    val :: Word32)

    #if defined(ENABLE_OVERLOADING)
    data TuplesLenFieldInfo
    instance AttrInfo TuplesLenFieldInfo where
        type AttrBaseTypeConstraint TuplesLenFieldInfo = (~) Tuples
        type AttrAllowedOps TuplesLenFieldInfo = '[ 'AttrSet, 'AttrGet]
        type AttrSetTypeConstraint TuplesLenFieldInfo = (~) Word32
        type AttrTransferTypeConstraint TuplesLenFieldInfo = (~)Word32
        type AttrTransferType TuplesLenFieldInfo = Word32
        type AttrGetType TuplesLenFieldInfo = Word32
        type AttrLabel TuplesLenFieldInfo = "len"
        type AttrOrigin TuplesLenFieldInfo = Tuples
        attrGet = getTuplesLen
        attrSet = setTuplesLen
        attrConstruct = undefined
        attrClear = undefined
        attrTransfer _ v = do
            return v
        dbgAttrInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.GLib.Structs.Tuples.len"
            , O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-Tuples.html#g:attr:len"
            })

    tuples_len :: AttrLabelProxy "len"
    tuples_len = AttrLabelProxy

    #endif

    #if defined(ENABLE_OVERLOADING)
    instance O.HasAttributeList Tuples
    type instance O.AttributeList Tuples = TuplesAttributeList
    type TuplesAttributeList = ('[ '("len", TuplesLenFieldInfo)] :: [(Symbol, DK.Type)])
    #endif

    -- method Tuples::destroy
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "tuples"
    --           , argType =
    --               TInterface Name { namespace = "GLib" , name = "Tuples" }
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "the tuple data to free."
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Nothing
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tuples_destroy" g_tuples_destroy ::
        Ptr Tuples ->                           -- tuples : TInterface (Name {namespace = "GLib", name = "Tuples"})
        IO ()

    {-# DEPRECATED tuplesDestroy ["(Since version 2.26)","Rarely used API"] #-}
    -- | Frees the records which were returned by @/g_relation_select()/@. This
    -- should always be called after @/g_relation_select()/@ when you are
    -- finished with the records. The records are not removed from the
    -- t'GI.GLib.Structs.Relation.Relation'.
    tuplesDestroy ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tuples
        -- ^ /@tuples@/: the tuple data to free.
        -> m ()
    tuplesDestroy :: forall (m :: * -> *). (HasCallStack, MonadIO m) => Tuples -> m ()
    tuplesDestroy Tuples
    tuples = IO () -> m ()
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO () -> m ()) -> IO () -> m ()
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr Tuples
    tuples' <- Tuples -> IO (Ptr Tuples)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Tuples
    tuples
        Ptr Tuples -> IO ()
    g_tuples_destroy Ptr Tuples
    tuples'
        Tuples -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr Tuples
    tuples
        () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()

    #if defined(ENABLE_OVERLOADING)
    data TuplesDestroyMethodInfo
    instance (signature ~ (m ()), MonadIO m) => O.OverloadedMethod TuplesDestroyMethodInfo Tuples signature where
        overloadedMethod = tuplesDestroy

    instance O.OverloadedMethodInfo TuplesDestroyMethodInfo Tuples where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.GLib.Structs.Tuples.tuplesDestroy",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-Tuples.html#v:tuplesDestroy"
            })

    #endif

    -- method Tuples::index
    -- method type : OrdinaryMethod
    -- Args: [ Arg
    --           { argCName = "tuples"
    --           , argType =
    --               TInterface Name { namespace = "GLib" , name = "Tuples" }
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText =
    --                     Just "the tuple data, returned by g_relation_select()."
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       , Arg
    --           { argCName = "index_"
    --           , argType = TBasicType TInt
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "the index of the record."
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       , Arg
    --           { argCName = "field"
    --           , argType = TBasicType TInt
    --           , direction = DirectionIn
    --           , mayBeNull = False
    --           , argDoc =
    --               Documentation
    --                 { rawDocText = Just "the field to return."
    --                 , sinceVersion = Nothing
    --                 }
    --           , argScope = ScopeTypeInvalid
    --           , argClosure = -1
    --           , argDestroy = -1
    --           , argCallerAllocates = False
    --           , argCallbackUserData = False
    --           , transfer = TransferNothing
    --           }
    --       ]
    -- Lengths: []
    -- returnType: Just (TBasicType TPtr)
    -- throws : False
    -- Skip return : False

    foreign import ccall "g_tuples_index" g_tuples_index ::
        Ptr Tuples ->                           -- tuples : TInterface (Name {namespace = "GLib", name = "Tuples"})
        Int32 ->                                -- index_ : TBasicType TInt
        Int32 ->                                -- field : TBasicType TInt
        IO (Ptr ())

    {-# DEPRECATED tuplesIndex ["(Since version 2.26)","Rarely used API"] #-}
    -- | Gets a field from the records returned by @/g_relation_select()/@. It
    -- returns the given field of the record at the given index. The
    -- returned value should not be changed.
    tuplesIndex ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        Tuples
        -- ^ /@tuples@/: the tuple data, returned by @/g_relation_select()/@.
        -> Int32
        -- ^ /@index_@/: the index of the record.
        -> Int32
        -- ^ /@field@/: the field to return.
        -> m (Ptr ())
        -- ^ __Returns:__ the field of the record.
    tuplesIndex :: forall (m :: * -> *).
    (HasCallStack, MonadIO m) =>
    Tuples -> Int32 -> Int32 -> m (Ptr ())
    tuplesIndex Tuples
    tuples Int32
    index_ Int32
    field = IO (Ptr ()) -> m (Ptr ())
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (Ptr ()) -> m (Ptr ())) -> IO (Ptr ()) -> m (Ptr ())
    forall a b. (a -> b) -> a -> b
    $ do
        Ptr Tuples
    tuples' <- Tuples -> IO (Ptr Tuples)
    forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
    unsafeManagedPtrGetPtr Tuples
    tuples
        Ptr ()
    result <- Ptr Tuples -> Int32 -> Int32 -> IO (Ptr ())
    g_tuples_index Ptr Tuples
    tuples' Int32
    index_ Int32
    field
        Tuples -> IO ()
    forall a. ManagedPtrNewtype a => a -> IO ()
    touchManagedPtr Tuples
    tuples
        Ptr () -> IO (Ptr ())
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return Ptr ()
    result

    #if defined(ENABLE_OVERLOADING)
    data TuplesIndexMethodInfo
    instance (signature ~ (Int32 -> Int32 -> m (Ptr ())), MonadIO m) => O.OverloadedMethod TuplesIndexMethodInfo Tuples signature where
        overloadedMethod = tuplesIndex

    instance O.OverloadedMethodInfo TuplesIndexMethodInfo Tuples where
        overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
            O.resolvedSymbolName = "GI.GLib.Structs.Tuples.tuplesIndex",
            O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-glib-2.0.30/docs/GI-GLib-Structs-Tuples.html#v:tuplesIndex"
            })

    #endif

    #if defined(ENABLE_OVERLOADING)
    type family ResolveTuplesMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
        ResolveTuplesMethod "destroy" o = TuplesDestroyMethodInfo
        ResolveTuplesMethod "index" o = TuplesIndexMethodInfo
        ResolveTuplesMethod l o = O.MethodResolutionFailed l o

    instance (info ~ ResolveTuplesMethod t Tuples, O.OverloadedMethod info Tuples p) => OL.IsLabel t (Tuples -> p) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.overloadedMethod @info
    #else
        fromLabel _ = O.overloadedMethod @info
    #endif

    #if MIN_VERSION_base(4,13,0)
    instance (info ~ ResolveTuplesMethod t Tuples, O.OverloadedMethod info Tuples p, R.HasField t Tuples p) => R.HasField t Tuples p where
        getField = O.overloadedMethod @info

    #endif

    instance (info ~ ResolveTuplesMethod t Tuples, O.OverloadedMethodInfo info Tuples) => OL.IsLabel t (O.MethodProxy info Tuples) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.MethodProxy
    #else
        fromLabel _ = O.MethodProxy
    #endif

    #endif