{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

Represents a multipart HTTP message body, parsed according to the
syntax of RFC 2046. Of particular interest to HTTP are
\<literal>multipart\/byte-ranges\<\/literal> and
\<literal>multipart\/form-data\<\/literal>.

Although the headers of a 'GI.Soup.Structs.Multipart.Multipart' body part will contain the
full headers from that body part, libsoup does not interpret them
according to MIME rules. For example, each body part is assumed to
have \"binary\" Content-Transfer-Encoding, even if its headers
explicitly state otherwise. In other words, don\'t try to use
'GI.Soup.Structs.Multipart.Multipart' for handling real MIME multiparts.
-}

module GI.Soup.Structs.Multipart
    ( 

-- * Exported types
    Multipart(..)                           ,
    noMultipart                             ,


 -- * Methods
-- ** appendFormFile #method:appendFormFile#
    MultipartAppendFormFileMethodInfo       ,
    multipartAppendFormFile                 ,


-- ** appendFormString #method:appendFormString#
    MultipartAppendFormStringMethodInfo     ,
    multipartAppendFormString               ,


-- ** appendPart #method:appendPart#
    MultipartAppendPartMethodInfo           ,
    multipartAppendPart                     ,


-- ** free #method:free#
    MultipartFreeMethodInfo                 ,
    multipartFree                           ,


-- ** getLength #method:getLength#
    MultipartGetLengthMethodInfo            ,
    multipartGetLength                      ,


-- ** getPart #method:getPart#
    MultipartGetPartMethodInfo              ,
    multipartGetPart                        ,


-- ** new #method:new#
    multipartNew                            ,


-- ** newFromMessage #method:newFromMessage#
    multipartNewFromMessage                 ,


-- ** toMessage #method:toMessage#
    MultipartToMessageMethodInfo            ,
    multipartToMessage                      ,




    ) 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.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP

import {-# SOURCE #-} qualified GI.Soup.Structs.Buffer as Soup.Buffer
import {-# SOURCE #-} qualified GI.Soup.Structs.MessageBody as Soup.MessageBody
import {-# SOURCE #-} qualified GI.Soup.Structs.MessageHeaders as Soup.MessageHeaders

newtype Multipart = Multipart (ManagedPtr Multipart)
foreign import ccall "soup_multipart_get_type" c_soup_multipart_get_type :: 
    IO GType

instance BoxedObject Multipart where
    boxedType _ = c_soup_multipart_get_type

noMultipart :: Maybe Multipart
noMultipart = Nothing


instance O.HasAttributeList Multipart
type instance O.AttributeList Multipart = MultipartAttributeList
type MultipartAttributeList = ('[ ] :: [(Symbol, *)])

-- method Multipart::new
-- method type : Constructor
-- Args : [Arg {argCName = "mime_type", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the MIME type of the multipart to create.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Multipart"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_new" soup_multipart_new :: 
    CString ->                              -- mime_type : TBasicType TUTF8
    IO (Ptr Multipart)

{- |
Creates a new empty 'GI.Soup.Structs.Multipart.Multipart' with a randomly-generated
boundary string. Note that /@mimeType@/ must be the full MIME type,
including \"multipart\/\".

@since 2.26
-}
multipartNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@mimeType@/: the MIME type of the multipart to create. -}
    -> m Multipart
    {- ^ __Returns:__ a new empty 'GI.Soup.Structs.Multipart.Multipart' of the given /@mimeType@/ -}
multipartNew mimeType = liftIO $ do
    mimeType' <- textToCString mimeType
    result <- soup_multipart_new mimeType'
    checkUnexpectedReturnNULL "multipartNew" result
    result' <- (wrapBoxed Multipart) result
    freeMem mimeType'
    return result'

-- method Multipart::new_from_message
-- method type : Constructor
-- Args : [Arg {argCName = "headers", argType = TInterface (Name {namespace = "Soup", name = "MessageHeaders"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the headers of the HTTP message to parse", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the body of the HTTP message to parse", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Soup", name = "Multipart"}))
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_new_from_message" soup_multipart_new_from_message :: 
    Ptr Soup.MessageHeaders.MessageHeaders -> -- headers : TInterface (Name {namespace = "Soup", name = "MessageHeaders"})
    Ptr Soup.MessageBody.MessageBody ->     -- body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
    IO (Ptr Multipart)

{- |
Parses /@headers@/ and /@body@/ to form a new 'GI.Soup.Structs.Multipart.Multipart'

@since 2.26
-}
multipartNewFromMessage ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Soup.MessageHeaders.MessageHeaders
    {- ^ /@headers@/: the headers of the HTTP message to parse -}
    -> Soup.MessageBody.MessageBody
    {- ^ /@body@/: the body of the HTTP message to parse -}
    -> m (Maybe Multipart)
    {- ^ __Returns:__ a new 'GI.Soup.Structs.Multipart.Multipart' (or 'Nothing' if the
message couldn\'t be parsed or wasn\'t multipart). -}
multipartNewFromMessage headers body = liftIO $ do
    headers' <- unsafeManagedPtrGetPtr headers
    body' <- unsafeManagedPtrGetPtr body
    result <- soup_multipart_new_from_message headers' body'
    maybeResult <- convertIfNonNull result $ \result' -> do
        result'' <- (wrapBoxed Multipart) result'
        return result''
    touchManagedPtr headers
    touchManagedPtr body
    return maybeResult

-- method Multipart::append_form_file
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a multipart (presumably of type \"multipart/form-data\")", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "control_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the control associated with this file", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the file, or %NULL if not known", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "content_type", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the MIME type of the file, or %NULL if not known", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the file data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_append_form_file" soup_multipart_append_form_file :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    CString ->                              -- control_name : TBasicType TUTF8
    CString ->                              -- filename : TBasicType TUTF8
    CString ->                              -- content_type : TBasicType TUTF8
    Ptr Soup.Buffer.Buffer ->               -- body : TInterface (Name {namespace = "Soup", name = "Buffer"})
    IO ()

{- |
Adds a new MIME part containing /@body@/ to /@multipart@/, using
\"Content-Disposition: form-data\", as per the HTML forms
specification. See 'GI.Soup.Functions.formRequestNewFromMultipart' for more
details.

@since 2.26
-}
multipartAppendFormFile ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a multipart (presumably of type \"multipart\/form-data\") -}
    -> T.Text
    {- ^ /@controlName@/: the name of the control associated with this file -}
    -> T.Text
    {- ^ /@filename@/: the name of the file, or 'Nothing' if not known -}
    -> T.Text
    {- ^ /@contentType@/: the MIME type of the file, or 'Nothing' if not known -}
    -> Soup.Buffer.Buffer
    {- ^ /@body@/: the file data -}
    -> m ()
multipartAppendFormFile multipart controlName filename contentType body = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    controlName' <- textToCString controlName
    filename' <- textToCString filename
    contentType' <- textToCString contentType
    body' <- unsafeManagedPtrGetPtr body
    soup_multipart_append_form_file multipart' controlName' filename' contentType' body'
    touchManagedPtr multipart
    touchManagedPtr body
    freeMem controlName'
    freeMem filename'
    freeMem contentType'
    return ()

data MultipartAppendFormFileMethodInfo
instance (signature ~ (T.Text -> T.Text -> T.Text -> Soup.Buffer.Buffer -> m ()), MonadIO m) => O.MethodInfo MultipartAppendFormFileMethodInfo Multipart signature where
    overloadedMethod _ = multipartAppendFormFile

-- method Multipart::append_form_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a multipart (presumably of type \"multipart/form-data\")", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "control_name", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the control associated with @data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "data", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the body data", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_append_form_string" soup_multipart_append_form_string :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    CString ->                              -- control_name : TBasicType TUTF8
    CString ->                              -- data : TBasicType TUTF8
    IO ()

{- |
Adds a new MIME part containing /@data@/ to /@multipart@/, using
\"Content-Disposition: form-data\", as per the HTML forms
specification. See 'GI.Soup.Functions.formRequestNewFromMultipart' for more
details.

@since 2.26
-}
multipartAppendFormString ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a multipart (presumably of type \"multipart\/form-data\") -}
    -> T.Text
    {- ^ /@controlName@/: the name of the control associated with /@data@/ -}
    -> T.Text
    {- ^ /@data@/: the body data -}
    -> m ()
multipartAppendFormString multipart controlName data_ = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    controlName' <- textToCString controlName
    data_' <- textToCString data_
    soup_multipart_append_form_string multipart' controlName' data_'
    touchManagedPtr multipart
    freeMem controlName'
    freeMem data_'
    return ()

data MultipartAppendFormStringMethodInfo
instance (signature ~ (T.Text -> T.Text -> m ()), MonadIO m) => O.MethodInfo MultipartAppendFormStringMethodInfo Multipart signature where
    overloadedMethod _ = multipartAppendFormString

-- method Multipart::append_part
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMultipart", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "headers", argType = TInterface (Name {namespace = "Soup", name = "MessageHeaders"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the MIME part headers", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "Buffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the MIME part body", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_append_part" soup_multipart_append_part :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    Ptr Soup.MessageHeaders.MessageHeaders -> -- headers : TInterface (Name {namespace = "Soup", name = "MessageHeaders"})
    Ptr Soup.Buffer.Buffer ->               -- body : TInterface (Name {namespace = "Soup", name = "Buffer"})
    IO ()

{- |
Adds a new MIME part to /@multipart@/ with the given headers and body.
(The multipart will make its own copies of /@headers@/ and /@body@/, so
you should free your copies if you are not using them for anything
else.)

@since 2.26
-}
multipartAppendPart ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a 'GI.Soup.Structs.Multipart.Multipart' -}
    -> Soup.MessageHeaders.MessageHeaders
    {- ^ /@headers@/: the MIME part headers -}
    -> Soup.Buffer.Buffer
    {- ^ /@body@/: the MIME part body -}
    -> m ()
multipartAppendPart multipart headers body = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    headers' <- unsafeManagedPtrGetPtr headers
    body' <- unsafeManagedPtrGetPtr body
    soup_multipart_append_part multipart' headers' body'
    touchManagedPtr multipart
    touchManagedPtr headers
    touchManagedPtr body
    return ()

data MultipartAppendPartMethodInfo
instance (signature ~ (Soup.MessageHeaders.MessageHeaders -> Soup.Buffer.Buffer -> m ()), MonadIO m) => O.MethodInfo MultipartAppendPartMethodInfo Multipart signature where
    overloadedMethod _ = multipartAppendPart

-- method Multipart::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMultipart", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_free" soup_multipart_free :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    IO ()

{- |
Frees /@multipart@/

@since 2.26
-}
multipartFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a 'GI.Soup.Structs.Multipart.Multipart' -}
    -> m ()
multipartFree multipart = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    soup_multipart_free multipart'
    touchManagedPtr multipart
    return ()

data MultipartFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo MultipartFreeMethodInfo Multipart signature where
    overloadedMethod _ = multipartFree

-- method Multipart::get_length
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMultipart", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_get_length" soup_multipart_get_length :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    IO Int32

{- |
Gets the number of body parts in /@multipart@/

@since 2.26
-}
multipartGetLength ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a 'GI.Soup.Structs.Multipart.Multipart' -}
    -> m Int32
    {- ^ __Returns:__ the number of body parts in /@multipart@/ -}
multipartGetLength multipart = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    result <- soup_multipart_get_length multipart'
    touchManagedPtr multipart
    return result

data MultipartGetLengthMethodInfo
instance (signature ~ (m Int32), MonadIO m) => O.MethodInfo MultipartGetLengthMethodInfo Multipart signature where
    overloadedMethod _ = multipartGetLength

-- method Multipart::get_part
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMultipart", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "part", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the part number to get (counting from 0)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "headers", argType = TInterface (Name {namespace = "Soup", name = "MessageHeaders"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "return location for the MIME part\nheaders", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "body", argType = TInterface (Name {namespace = "Soup", name = "Buffer"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "return location for the MIME part\nbody", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_get_part" soup_multipart_get_part :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    Int32 ->                                -- part : TBasicType TInt
    Ptr (Ptr Soup.MessageHeaders.MessageHeaders) -> -- headers : TInterface (Name {namespace = "Soup", name = "MessageHeaders"})
    Ptr (Ptr Soup.Buffer.Buffer) ->         -- body : TInterface (Name {namespace = "Soup", name = "Buffer"})
    IO CInt

{- |
Gets the indicated body part from /@multipart@/.

@since 2.26
-}
multipartGetPart ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a 'GI.Soup.Structs.Multipart.Multipart' -}
    -> Int32
    {- ^ /@part@/: the part number to get (counting from 0) -}
    -> m (Bool,Soup.MessageHeaders.MessageHeaders,Soup.Buffer.Buffer)
    {- ^ __Returns:__ 'True' on success, 'False' if /@part@/ is out of range (in
which case /@headers@/ and /@body@/ won\'t be set) -}
multipartGetPart multipart part = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    headers <- allocMem :: IO (Ptr (Ptr Soup.MessageHeaders.MessageHeaders))
    body <- allocMem :: IO (Ptr (Ptr Soup.Buffer.Buffer))
    result <- soup_multipart_get_part multipart' part headers body
    let result' = (/= 0) result
    headers' <- peek headers
    headers'' <- (newBoxed Soup.MessageHeaders.MessageHeaders) headers'
    body' <- peek body
    body'' <- (newBoxed Soup.Buffer.Buffer) body'
    touchManagedPtr multipart
    freeMem headers
    freeMem body
    return (result', headers'', body'')

data MultipartGetPartMethodInfo
instance (signature ~ (Int32 -> m (Bool,Soup.MessageHeaders.MessageHeaders,Soup.Buffer.Buffer)), MonadIO m) => O.MethodInfo MultipartGetPartMethodInfo Multipart signature where
    overloadedMethod _ = multipartGetPart

-- method Multipart::to_message
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "multipart", argType = TInterface (Name {namespace = "Soup", name = "Multipart"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #SoupMultipart", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dest_headers", argType = TInterface (Name {namespace = "Soup", name = "MessageHeaders"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the headers of the HTTP message to serialize @multipart to", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "dest_body", argType = TInterface (Name {namespace = "Soup", name = "MessageBody"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the body of the HTTP message to serialize @multipart to", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "soup_multipart_to_message" soup_multipart_to_message :: 
    Ptr Multipart ->                        -- multipart : TInterface (Name {namespace = "Soup", name = "Multipart"})
    Ptr Soup.MessageHeaders.MessageHeaders -> -- dest_headers : TInterface (Name {namespace = "Soup", name = "MessageHeaders"})
    Ptr Soup.MessageBody.MessageBody ->     -- dest_body : TInterface (Name {namespace = "Soup", name = "MessageBody"})
    IO ()

{- |
Serializes /@multipart@/ to /@destHeaders@/ and /@destBody@/.

@since 2.26
-}
multipartToMessage ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Multipart
    {- ^ /@multipart@/: a 'GI.Soup.Structs.Multipart.Multipart' -}
    -> Soup.MessageHeaders.MessageHeaders
    {- ^ /@destHeaders@/: the headers of the HTTP message to serialize /@multipart@/ to -}
    -> Soup.MessageBody.MessageBody
    {- ^ /@destBody@/: the body of the HTTP message to serialize /@multipart@/ to -}
    -> m ()
multipartToMessage multipart destHeaders destBody = liftIO $ do
    multipart' <- unsafeManagedPtrGetPtr multipart
    destHeaders' <- unsafeManagedPtrGetPtr destHeaders
    destBody' <- unsafeManagedPtrGetPtr destBody
    soup_multipart_to_message multipart' destHeaders' destBody'
    touchManagedPtr multipart
    touchManagedPtr destHeaders
    touchManagedPtr destBody
    return ()

data MultipartToMessageMethodInfo
instance (signature ~ (Soup.MessageHeaders.MessageHeaders -> Soup.MessageBody.MessageBody -> m ()), MonadIO m) => O.MethodInfo MultipartToMessageMethodInfo Multipart signature where
    overloadedMethod _ = multipartToMessage

type family ResolveMultipartMethod (t :: Symbol) (o :: *) :: * where
    ResolveMultipartMethod "appendFormFile" o = MultipartAppendFormFileMethodInfo
    ResolveMultipartMethod "appendFormString" o = MultipartAppendFormStringMethodInfo
    ResolveMultipartMethod "appendPart" o = MultipartAppendPartMethodInfo
    ResolveMultipartMethod "free" o = MultipartFreeMethodInfo
    ResolveMultipartMethod "toMessage" o = MultipartToMessageMethodInfo
    ResolveMultipartMethod "getLength" o = MultipartGetLengthMethodInfo
    ResolveMultipartMethod "getPart" o = MultipartGetPartMethodInfo
    ResolveMultipartMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveMultipartMethod t Multipart, O.MethodInfo info Multipart p) => O.IsLabelProxy t (Multipart -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveMultipartMethod t Multipart, O.MethodInfo info Multipart p) => O.IsLabel t (Multipart -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif