import t, c
from stdint import *
from vqt6._types import *

# ============================================================
# vqt6/_qtcore.py — QtCore 的 t.State FFI 声明
#
# 所有函数都是 C 桥接层 (libvqt6_bridge.a) 的 extern "C" 函数
# 命名规范: vqt6_<class>_<action>
# ============================================================

# ============================================================
# QString — UTF-16 字符串
# ============================================================
# 创建 QString（从 UTF-8 C 字符串）
def vqt6_qstring_create(utf8: t.CChar | t.CPtr) -> QtStringPtr | t.State: pass

# 获取 QString 的 UTF-8 表示（写入 buf，返回实际长度，不含 \0）
# buf 需足够大（建议 4 * qstring.length() + 1）
def vqt6_qstring_to_utf8(qstr: QtStringPtr, buf: t.CChar | t.CPtr, buf_size: t.CSizeT) -> t.CSizeT | t.State: pass

# 释放 QString
def vqt6_qstring_free(qstr: QtStringPtr) -> t.State: pass

# 获取 QString 字符数
def vqt6_qstring_length(qstr: QtStringPtr) -> t.CInt | t.State: pass

# QString 是否为空
def vqt6_qstring_is_empty(qstr: QtStringPtr) -> t.CInt | t.State: pass

# QString 比较
def vqt6_qstring_equals(qstr: QtStringPtr, other: QtStringPtr) -> t.CInt | t.State: pass

# QString 拼接（返回新 QString）
def vqt6_qstring_append(qstr: QtStringPtr, other: QtStringPtr) -> QtStringPtr | t.State: pass


# ============================================================
# QByteArray — 字节数组
# ============================================================
def vqt6_qbytearray_create(data: t.CVoid | t.CPtr, size: t.CSizeT) -> QtByteArrayPtr | t.State: pass
def vqt6_qbytearray_data(qba: QtByteArrayPtr, out_size: t.CSizeT | t.CPtr) -> t.CVoid | t.CPtr | t.State: pass
def vqt6_qbytearray_size(qba: QtByteArrayPtr) -> t.CSizeT | t.State: pass
def vqt6_qbytearray_free(qba: QtByteArrayPtr) -> t.State: pass


# ============================================================
# QObject — 所有 Qt 对象的基类
# ============================================================
# 注意: Qt 对象的内存由 C++ 管理，Viper 端不应直接 free
def vqt6_qobject_delete(obj: QtObjectPtr) -> t.State: pass
def vqt6_qobject_delete_later(obj: QtObjectPtr) -> t.State: pass
def vqt6_qobject_set_object_name(obj: QtObjectPtr, name: QtStringPtr) -> t.State: pass
def vqt6_qobject_object_name(obj: QtObjectPtr) -> QtStringPtr | t.State: pass
def vqt6_qobject_set_parent(child: QtObjectPtr, parent: QtObjectPtr) -> t.State: pass
def vqt6_qobject_parent(obj: QtObjectPtr) -> QtObjectPtr | t.State: pass

# 信号/槽连接 (简化版: 函数指针形式)
# typedef void (*vqt6_callback_t)(void* user_data);
# vqt6_qobject_connect_typed(sender, signal_id, receiver, slot_id, type) 由 C++ 桥接层处理
# 由于函数指针在 C ABI 中复杂，我们采用字符串 signal/slot 名 + 全局回调注册表
def vqt6_qobject_connect(sender: QtObjectPtr, signal_name: t.CChar | t.CPtr,
                          receiver: QtObjectPtr, slot_name: t.CChar | t.CPtr) -> t.CInt | t.State: pass

def vqt6_qobject_disconnect(sender: QtObjectPtr, signal_name: t.CChar | t.CPtr,
                             receiver: QtObjectPtr, slot_name: t.CChar | t.CPtr) -> t.CInt | t.State: pass

# 事件过滤器
def vqt6_qobject_install_event_filter(watched: QtObjectPtr, filter: QtObjectPtr) -> t.State: pass
def vqt6_qobject_remove_event_filter(watched: QtObjectPtr, filter: QtObjectPtr) -> t.State: pass


# ============================================================
# QCoreApplication — 事件循环基类
# ============================================================
def vqt6_qcoreapp_create(app_name: t.CChar | t.CPtr) -> QtCoreAppPtr | t.State: pass
def vqt6_qcoreapp_instance() -> QtCoreAppPtr | t.State: pass
def vqt6_qcoreapp_exec(app: QtCoreAppPtr) -> t.CInt | t.State: pass
def vqt6_qcoreapp_quit(app: QtCoreAppPtr, exit_code: t.CInt) -> t.State: pass
def vqt6_qcoreapp_exit(app: QtCoreAppPtr, exit_code: t.CInt) -> t.State: pass
def vqt6_qcoreapp_process_events(app: QtCoreAppPtr, flags: t.CInt) -> t.State: pass
def vqt6_qcoreapp_post_event(receiver: QtObjectPtr, event: QtEventPtr) -> t.State: pass
def vqt6_qcoreapp_send_event(receiver: QtObjectPtr, event: QtEventPtr) -> t.CInt | t.State: pass
def vqt6_qcoreapp_organization_name(app: QtCoreAppPtr) -> QtStringPtr | t.State: pass
def vqt6_qcoreapp_set_organization_name(app: QtCoreAppPtr, name: QtStringPtr) -> t.State: pass
def vqt6_qcoreapp_application_name(app: QtCoreAppPtr) -> QtStringPtr | t.State: pass
def vqt6_qcoreapp_set_application_name(app: QtCoreAppPtr, name: QtStringPtr) -> t.State: pass


# ============================================================
# QTimer — 定时器
# ============================================================
def vqt6_qtimer_create() -> QtTimerPtr | t.State: pass
def vqt6_qtimer_create_with_parent(parent: QtObjectPtr) -> QtTimerPtr | t.State: pass
def vqt6_qtimer_start(timer: QtTimerPtr, interval_ms: t.CInt) -> t.State: pass
def vqt6_qtimer_stop(timer: QtTimerPtr) -> t.State: pass
def vqt6_qtimer_set_interval(timer: QtTimerPtr, interval_ms: t.CInt) -> t.State: pass
def vqt6_qtimer_interval(timer: QtTimerPtr) -> t.CInt | t.State: pass
def vqt6_qtimer_is_active(timer: QtTimerPtr) -> t.CInt | t.State: pass
def vqt6_qtimer_set_single_shot(timer: QtTimerPtr, single_shot: t.CInt) -> t.State: pass
def vqt6_qtimer_is_single_shot(timer: QtTimerPtr) -> t.CInt | t.State: pass


# ============================================================
# QVariant — 通用数据容器
# ============================================================
def vqt6_qvariant_create_int(value: t.CInt) -> QtVariantPtr | t.State: pass
def vqt6_qvariant_create_double(value: t.CDouble) -> QtVariantPtr | t.State: pass
def vqt6_qvariant_create_bool(value: t.CInt) -> QtVariantPtr | t.State: pass
def vqt6_qvariant_create_string(s: QtStringPtr) -> QtVariantPtr | t.State: pass
def vqt6_qvariant_to_int(v: QtVariantPtr, ok: t.CInt | t.CPtr) -> t.CInt | t.State: pass
def vqt6_qvariant_to_double(v: QtVariantPtr, ok: t.CInt | t.CPtr) -> t.CDouble | t.State: pass
def vqt6_qvariant_to_bool(v: QtVariantPtr, ok: t.CInt | t.CPtr) -> t.CInt | t.State: pass
def vqt6_qvariant_to_string(v: QtVariantPtr) -> QtStringPtr | t.State: pass
def vqt6_qvariant_type_id(v: QtVariantPtr) -> t.CInt | t.State: pass
def vqt6_qvariant_is_valid(v: QtVariantPtr) -> t.CInt | t.State: pass
def vqt6_qvariant_free(v: QtVariantPtr) -> t.State: pass


# ============================================================
# QEvent — 事件基类
# ============================================================
def vqt6_qevent_type(event: QtEventPtr) -> t.CInt | t.State: pass
def vqt6_qevent_accept(event: QtEventPtr) -> t.State: pass
def vqt6_qevent_ignore(event: QtEventPtr) -> t.State: pass
def vqt6_qevent_is_accepted(event: QtEventPtr) -> t.CInt | t.State: pass


# ============================================================
# 字符串列表 (QStringList / QList<QString>)
# ============================================================
def vqt6_qstringlist_create() -> QtStringListPtr | t.State: pass
def vqt6_qstringlist_append(list: QtStringListPtr, str: QtStringPtr) -> t.State: pass
def vqt6_qstringlist_size(list: QtStringListPtr) -> t.CInt | t.State: pass
def vqt6_qstringlist_at(list: QtStringListPtr, index: t.CInt) -> QtStringPtr | t.State: pass
def vqt6_qstringlist_free(list: QtStringListPtr) -> t.State: pass


# ============================================================
# 字节数组列表 (QList<QByteArray>)
# ============================================================
def vqt6_qbytearraylist_create() -> QtByteArrayListPtr | t.State: pass
def vqt6_qbytearraylist_append(list: QtByteArrayListPtr, qba: QtByteArrayPtr) -> t.State: pass
def vqt6_qbytearraylist_size(list: QtByteArrayListPtr) -> t.CInt | t.State: pass
def vqt6_qbytearraylist_at(list: QtByteArrayListPtr, index: t.CInt) -> QtByteArrayPtr | t.State: pass
def vqt6_qbytearraylist_free(list: QtByteArrayListPtr) -> t.State: pass


# ============================================================
# 全局回调注册表
# ============================================================
# 用于从 C++ 端回调 Viper 代码
# Viper 注册一个 slot 函数（用整数 ID 标识），C++ 在触发信号时通过 ID 查找
# typedef void (*vqt6_slot_callback_t)(int slot_id, void* user_data);
def vqt6_register_slot(slot_id: t.CInt, user_data: t.CVoid | t.CPtr) -> t.State: pass
def vqt6_unregister_slot(slot_id: t.CInt) -> t.State: pass
def vqt6_trigger_slot(slot_id: t.CInt) -> t.State: pass  # 测试用
