<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
                      "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
    <interface name="net.buzzert.kordophone.Repository">
        <method name="GetVersion">
            <arg type="s" name="version" direction="out" />
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Returns the version of the client daemon."/>
        </method>

        <!-- Conversations -->

        <method name="GetConversations">
            <arg type="i" name="limit" direction="in"/>
            <arg type="i" name="offset" direction="in"/>

            <arg type="aa{sv}" direction="out" name="conversations">
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Array of dictionaries. Each dictionary has keys:
                                'id' (string): Unique identifier
                                'display_name' (string): Display name
                                'last_message_preview' (string): Preview text
                                'is_unread' (boolean): Unread status
                                'date' (int64): Date of last message
                                'participants' (array of strings): List of participants
                                'unread_count' (int32): Number of unread messages"/>
            </arg>
        </method>

        <method name="SyncConversationList">
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Initiates a background sync of the conversation list with the server."/>
        </method>

        <method name="SyncAllConversations">
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Initiates a background sync of all conversations with the server."/>
        </method>

        <method name="SyncConversation">
            <arg type="s" name="conversation_id" direction="in"/>
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Initiates a background sync of a single conversation with the server."/>
        </method>

        <method name="MarkConversationAsRead">
            <arg type="s" name="conversation_id" direction="in"/>
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Marks a conversation as read."/>
        </method>

        <signal name="ConversationsUpdated">
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Emitted when the list of conversations is updated."/>
        </signal>

        <method name="DeleteAllConversations">
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Deletes all conversations from the database."/>
        </method>

        <!-- Messages -->

        <method name="GetMessages">
            <arg type="s" name="conversation_id" direction="in"/>
            <arg type="s" name="last_message_id" direction="in"/>
            <arg type="aa{sv}" direction="out" name="messages">
                <annotation name="org.freedesktop.DBus.DocString"
                            value="Array of dictionaries. Each dictionary has keys:
                                    'id' (string): Unique message identifier
                                    'text' (string): Message body text
                                    'date' (int64): Message timestamp
                                    'sender' (string): Sender display name
                                    'attachments' (array of dictionaries): List of attachments
                                        'guid' (string): Attachment GUID
                                        'path' (string): Attachment path
                                        'preview_path' (string): Preview attachment path
                                        'downloaded' (boolean): Whether the attachment is downloaded
                                        'preview_downloaded' (boolean): Whether the preview is downloaded
                                        'metadata' (dictionary, optional): Attachment metadata
                                            'attribution_info' (dictionary, optional): Attribution info
                                                'width' (int32, optional): Width
                                                'height' (int32, optional): Height"/>
            </arg>
        </method>

        <method name="SendMessage">
            <arg type="s" name="conversation_id" direction="in"/>
            <arg type="s" name="text" direction="in"/>
            <arg type="as" name="attachment_guids" direction="in"/>

            <arg type="s" name="outgoing_message_id" direction="out"/>

            <annotation name="org.freedesktop.DBus.DocString"
                        value="Sends a message to the server. Returns the outgoing message ID.
                        Arguments:
                        - conversation_id: The ID of the conversation to send the message to.
                        - text: The text of the message to send.
                        - attachment_guids: The GUIDs of the attachments to send.

                        Returns:
                        - outgoing_message_id: The ID of the outgoing message.
                        "/>
        </method>

        <signal name="MessagesUpdated">
            <arg type="s" name="conversation_id" direction="in"/>
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Emitted when the list of messages is updated."/>
        </signal>

        <signal name="UpdateStreamReconnected">
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Emitted when the update stream is reconnected after a timeout or configuration change."/>
        </signal>

        <!-- Attachments -->

        <method name="GetAttachmentInfo">
            <arg type="s" name="attachment_id" direction="in"/>
            <arg type="(ssbb)" name="attachment_info" direction="out"/>

            <annotation name="org.freedesktop.DBus.DocString"
                        value="Returns attachment info: 
                            - path: string
                            - preview_path: string
                            - downloaded: boolean
                            - preview_downloaded: boolean
                        "/>
        </method>

        <method name="DownloadAttachment">
            <arg type="s" name="attachment_id" direction="in"/>
            <arg type="b" name="preview" direction="in"/>

            <annotation name="org.freedesktop.DBus.DocString"
                        value="Initiates download of the specified attachment if not already downloaded.
                        Arguments: 
                        attachment_id: the attachment GUID
                        preview: whether to download the preview (true) or full attachment (false)
                        "/>
        </method>

        <method name="UploadAttachment">
            <arg type="s" name="path" direction="in"/>
            <arg type="s" name="upload_guid" direction="out"/>
        </method>

        <signal name="AttachmentDownloadCompleted">
            <arg type="s" name="attachment_id"/>

            <annotation name="org.freedesktop.DBus.DocString"
                        value="Emitted when an attachment download completes successfully."/>
        </signal>

        <signal name="AttachmentDownloadFailed">
            <arg type="s" name="attachment_id"/>
            <arg type="s" name="error_message"/>
            <annotation name="org.freedesktop.DBus.DocString"
                        value="Emitted when an attachment download fails."/>
        </signal>

        <signal name="AttachmentUploadCompleted">
            <arg type="s" name="upload_guid"/>
            <arg type="s" name="attachment_guid"/>

            <annotation name="org.freedesktop.DBus.DocString"
                        value="Emitted when an attachment upload completes successfully.
                        Returns:
                        - upload_guid: The GUID of the upload.
                        - attachment_guid: The GUID of the attachment on the server.
                        "/>
        </signal>
    </interface>

    <interface name="net.buzzert.kordophone.Settings">
        <!-- editable properties -->
        <property name="ServerURL" type="s" access="readwrite"/>
        <property name="Username"  type="s" access="readwrite"/>

        <!-- helpers for atomic updates -->
        <method name="SetServer">
            <arg name="url"  type="s" direction="in"/>
            <arg name="user" type="s" direction="in"/>
        </method>

        <!-- emitted when anything changes -->
        <signal name="ConfigChanged"/>
    </interface>
</node>
