/*
 * Copyright (c) 2026 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef DRIVER_BLE_CLIENT_INTERFACE_H
#define DRIVER_BLE_CLIENT_INTERFACE_H

#include "driver_ble_struct.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif

/**
 * @brief 发起GATT连接请求
 *
 * 该函数用于建立与指定蓝牙设备的GATT连接。支持快速连接标志,可控制连接尝试的间隔和策略。
 *
 * @param addr 目标蓝牙地址指针,包含设备地址类型和地址信息
 * @param fastConnFlag 快速连接标志:true表示使用较短的连接间隔以加快连接速度,false表示使用标准连接间隔
 * @return 成功返回套接字文件描述符,失败返回负值错误码
 */
int DriverGattConnect(DriverBtAddr *addr, bool fastConnFlag);

/**
 * @brief 断开GATT客户端连接
 *
 * 该函数用于关闭指定的GATT连接套接字,释放相关资源。
 *
 * @param sock 要断开的GATT连接套接字描述符
 * @return 成功返回0,失败返回负值
 */
int32_t DriverGattcDisconnect(int sock);

/**
 * @brief 搜索GATT服务
 *
 * 在已建立的GATT连接上执行服务发现,获取对端设备的所有GATT服务和特征信息。
 *
 * @param sock GATT连接套接字描述符
 * @return 成功返回0,失败返回负值错误码
 */
int32_t DriverGattSearchServices(int sock);

/**
 * @brief 注册GATT通知
 *
 * 使能或注册对端设备的通知/指示功能,以便接收特征值的变化通知。
 *
 * @param sock GATT连接套接字描述符
 * @return 成功返回0,失败返回负值错误码
 */
int32_t DriverGattRegisterNotification(int sock);

/**
 * @brief 写入GATT特征值
 *
 * 向指定的特征句柄写入数据,支持带偏移的写入操作(由DriverGattcData结构体指定)。
 *
 * @param sock GATT连接套接字描述符
 * @param clientData 指向客户端数据结构的指针,包含写入偏移量、长度和数据缓冲区等信息
 * @param btChar 目标特征的结构体,包含特征UUID、属性等信息
 * @param handle 特征值句柄(用于快速定位特征)
 * @return 成功返回0,失败返回负值错误码
 */
int32_t DriverGattWriteCharacteristic(int sock, DriverGattcData *clientData, DriverGattCharacteristic btChar, uint16_t handle);

/**
 * @brief 配置GATT MTU大小
 *
 * 发起MTU交换请求,协商连接的最大传输单元(MTU)大小。
 *
 * @param sock GATT连接套接字描述符
 * @param mtuSize 客户端请求的MTU值(通常为23~517字节)
 * @return 成功返回0,失败返回负值错误码
 */
int32_t DriverGattConfigureMtuSize(int sock, int mtuSize);

/**
 * @brief 设置GATT连接优先级
 *
 * 调整GATT连接的参数优先级,例如连接间隔、延迟等,以优化功耗或数据传输性能。
 *
 * @param sock GATT连接套接字描述符
 * @param addr 目标蓝牙地址指针(可能用于验证或指定设备)
 * @param priority 要设置的优先级枚举值,如高、中、低
 * @return 成功返回0,失败返回负值错误码
 */
int32_t DriverGattSetPriority(int sock, DriverBtAddr *addr, DriverBleGattPriority priority);

#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif