/*
 * This file is auto-generated by jsongensource.py, Do not modify it directly!
 */

/*
 * Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
 *
 * 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.
 *
 */
#include "bt_avrcp_control.h"
#include "feature_bluetooth.h"
#include "system_bluetooth_bt_avrcpcontrol.h"

#define file_tag "system_bluetooth_bt_avrcpcontrol"

void system_bluetooth_bt_avrcpcontrol_onRegister(const char* feature_name)
{
    FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}

void system_bluetooth_bt_avrcpcontrol_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
    feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH_AVRCPCONTROL, handle);
    FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}

void system_bluetooth_bt_avrcpcontrol_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
    feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH_AVRCPCONTROL);
    FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}

void system_bluetooth_bt_avrcpcontrol_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
    feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH_AVRCPCONTROL);
    FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}

void system_bluetooth_bt_avrcpcontrol_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
    feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH_AVRCPCONTROL, handle);
    FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}

void system_bluetooth_bt_avrcpcontrol_onUnregister(const char* feature_name)
{
    FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}

FtCallbackId system_bluetooth_bt_avrcpcontrol_get_onElementattribute(void* feature, union AppendData append_data)
{
    return feature_bluetooth_get_feature_callback(feature, AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK);
}

void system_bluetooth_bt_avrcpcontrol_set_onElementattribute(void* feature, union AppendData append_data, FtCallbackId onElementattribute)
{
    FEATURE_LOG_DEBUG("set on avrcpcontrol set element attribute callback: %p, callbackId: %d", feature, onElementattribute);
    feature_bluetooth_set_feature_callback(feature, onElementattribute, AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK);
}

void system_bluetooth_bt_avrcpcontrol_wrap_startGetElementAttribute(FeatureInstanceHandle feature, union AppendData append_data, system_bluetooth_bt_avrcpcontrol_StartGetElementAttributeParams* params)
{
    bt_address_t addr;
    bt_status_t status;

    if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
        if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
            FEATURE_LOG_ERROR("invoke get element attribute fail callback failed!");
        }
        goto COMPLETE_CALLBACK;
    }

    status = bt_avrcp_control_get_element_attributes(feature_bluetooth_get_bt_ins(feature), &addr);

    if (status == BT_STATUS_SUCCESS) {
        if (!FeatureInvokeCallback(feature, params->success)) {
            FEATURE_LOG_ERROR("invoke get element attribute success  failed!");
        }
    } else {
        if (!FeatureInvokeCallback(feature, params->fail, "get element attribute failed!", status)) {
            FEATURE_LOG_ERROR("invoke get element attribute fail callback failed!");
        }
    }
COMPLETE_CALLBACK:
    if (!FeatureInvokeCallback(feature, params->complete)) {
        FEATURE_LOG_ERROR("invoke disconnect complete callback failed!");
    }

    FeatureRemoveCallback(feature, params->success);
    FeatureRemoveCallback(feature, params->fail);
    FeatureRemoveCallback(feature, params->complete);
}