"use strict";
/*
 * Copyright 2022-2024 Amazon.com, Inc. or its affiliates. All rights reserved.
 *
 * AMAZON PROPRIETARY/CONFIDENTIAL
 *
 * You may not use this file except in compliance with the terms and
 * conditions set forth in the accompanying LICENSE.TXT file.
 *
 * THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
 * DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
 * IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectivityController = void 0;
const react_native_1 = require("react-native");
const AccClientTurboModule_1 = __importDefault(require("./turbo-modules/AccClientTurboModule"));
const AccClientTypes_1 = require("./turbo-modules/AccClientTypes");
const Errors = __importStar(require("./turbo-modules/AccClientErrors"));
/**
 * @enum AccessoryControlEvent
 * @description Accessory Control Event Types
 */
var AccessoryControlEvent;
(function (AccessoryControlEvent) {
    /** Accessory discovered */
    AccessoryControlEvent["ACCESSORY_DISCOVERED"] = "accessory.event.ACCESSORY_DISCOVERED";
    /** Accessory discovery state changed */
    AccessoryControlEvent["DISCOVERY_STATE_CHANGED"] = "accessory.event.DISCOVERY_STATE_CHANGED";
    /** Accessory pair state changed */
    AccessoryControlEvent["PAIR_STATE_CHANGED"] = "accessory.event.PAIR_STATE_CHANGED";
    /** Accessory connect state changed */
    AccessoryControlEvent["CONNECT_STATE_CHANGED"] = "accessory.event.CONNECT_STATE_CHANGED";
    /** Accessory autopaired */
    AccessoryControlEvent["ACCESSORY_AUTOPAIRED"] = "accessory.event.ACCESSORY_AUTOPAIRED";
    /** Accessory autopair state changed */
    AccessoryControlEvent["AUTOPAIR_STATE_CHANGED"] = "accessory.event.AUTOPAIR_STATE_CHANGED";
    /** Accessory pairing request received */
    AccessoryControlEvent["PAIRING_REQUEST_RECEIVED"] = "accessory.event.PAIRING_REQUEST_RECEIVED";
    /** Accessory information updated */
    AccessoryControlEvent["ACCESSORY_INFO_UPDATED"] = "accessory.event.ACCESSORY_INFO_UPDATED";
    /** Accessory DFU state changed */
    AccessoryControlEvent["DFU_STATE_CHANGED"] = "accessory.event.DFU_STATE_CHANGED";
})(AccessoryControlEvent || (AccessoryControlEvent = {}));
/**
 * Throw specific Errors according to {AccessoryControlStatus}.
 * @param status - The code of {AccessoryControlStatus}.
 */
function throwException(status) {
    switch (status) {
        case AccClientTypes_1.AccessoryControlStatus.TIMEOUT:
            throw new Errors.TimeOutError();
        case AccClientTypes_1.AccessoryControlStatus.IN_PROGRESS:
            throw new Errors.InProgressError();
        case AccClientTypes_1.AccessoryControlStatus.NO_MEMORY:
            throw new Errors.OutOfMemoryError();
        case AccClientTypes_1.AccessoryControlStatus.NO_RESOURCE:
            throw new Errors.OutOfResourceError();
        case AccClientTypes_1.AccessoryControlStatus.NOT_FOUND:
            throw new Errors.NotFoundError();
        case AccClientTypes_1.AccessoryControlStatus.NOT_SUPPORTED:
            throw new Errors.NotSupportedError();
        case AccClientTypes_1.AccessoryControlStatus.NOT_PERMITTED:
            throw new Errors.NoPermissionError();
        case AccClientTypes_1.AccessoryControlStatus.NOT_CONNECTED:
            throw new Errors.NotConnectedError();
        case AccClientTypes_1.AccessoryControlStatus.TRY_AGAIN:
            throw new Errors.TryAgainError();
        default:
            throw new Errors.AccessoryError(status);
    }
}
/**
 * The default duration, in seconds, for device discovery.
 */
const DEFAULT_DISCOVERY_DURATION = 30;
/**
 * The default duration, in seconds, for the device to be visible.
 */
const DEFAULT_VISIBLE_DURATION = 120;
/**
 * The default duration, in seconds, for automatic pairing.
 */
const DEFAULT_AUTO_PAIR_DURATION = 120;
/**
 * @module AccClient
 *
 * @class ConnectivityController
 *
 * Instance of this class represents an ConnectivityController interface, providing a set of
 * APIs for accessory management (e.g discovering, pairing, connecting and disconnecting).
 *
 * The goal is to provide a set of APIs that can work with multiple protocols, in a protocol
 * agnostic way. However, it also allows the application to explictly express its intention to
 * specially work with specific protocol (e.g when performing accessory discovery and pairing).
 *
 * An application process can only have one instance of this class. When instatiating, please
 * provide an instance of an application implemented ConnectivityControllerEventDelegate class that
 * will be used to handle event callbacks. After that, application needs to call `initialize()`
 * which connects to the service component.
 */
class ConnectivityController extends react_native_1.NativeEventEmitter {
    clientCallbacks = {};
    initialized = false;
    checkInitiazationState() {
        if (this.initialized === false) {
            console.log('AccClient - start initialization');
            const status = AccClientTurboModule_1.default.initialize(this.clientEventDispatcher);
            if (status === AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
                this.initialized = true;
            }
            else {
                throwException(status);
            }
        }
    }
    /**
     * @brief constructor for ConnectivityController
     *
     * @param[in] callbacks application provided event callbacks.
     */
    constructor(callbacks) {
        // @ts-ignore
        super(AccClientTurboModule_1.default);
        this.clientCallbacks = callbacks;
    }
    /**
     * @brief Get major version number.
     * @return Major version number.
     */
    static getMajorVersion() {
        return AccClientTurboModule_1.default.getMajorVersion();
    }
    /**
     * @brief Get minor version number.
     * @return Minor version number.
     */
    static getMinorVersion() {
        return AccClientTurboModule_1.default.getMinorVersion();
    }
    /**
     * @brief Get patch version number.
     * @return Patch version number.
     */
    static getPatchVersion() {
        return AccClientTurboModule_1.default.getPatchVersion();
    }
    /**
     * @brief initialize as a client to ACC server.
     *
     * @privilege com.amazon.acc.privilege.access
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfMemoryError} Thrown when there is insufficient memory.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async initialize() {
        this.checkInitiazationState();
        await this.getAccessoryList(AccClientTypes_1.AccessoryListType.DISCOVERED);
        await this.getAccessoryList(AccClientTypes_1.AccessoryListType.PAIRED);
        await this.getAccessoryList(AccClientTypes_1.AccessoryListType.CONNECTED);
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Deinitialize as a client to ACC server.
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async deinitialize() {
        if (this.initialized === false) {
            return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
        }
        const response = await AccClientTurboModule_1.default.deinitialize();
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Start accessory discovery
     *
     * @privilege com.amazon.acc.privilege.discover
     * @privilege com.amazon.location.privilege.access.fine
     *
     * @param[in] protocol Protocol bridge to start discovery
     * @param[in] category Accessory category to be discovered
     * @param[in] duration Accessory discovery duration in seconds, default to be 30 seconds
     * if not specified by the caller.
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NotSupportedError} Thrown when the operation is not supported.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async startAccessoryDiscovery(protocol, category, duration) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.startAccessoryDiscovery(protocol, category, duration === undefined ? DEFAULT_DISCOVERY_DURATION : duration);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Cancel accessory discovery
     *
     * @privilege com.amazon.acc.privilege.discover
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NotSupportedError} Thrown when the operation is not supported.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async cancelAccessoryDiscovery(protocol) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.cancelAccessoryDiscovery(protocol);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Set local device visibility mode
     *
     * @privilege com.amazon.acc.privilege.discoverable
     *
     * @param[in] protocol Accessory protocol
     * @param[in] visibility Local device visibility mode
     * @param[in] duration Accessory discoverable duration in seconds when visibility
     * is set to LocalDeviceVisibility.CONNECTABLE_DISCOVERABLE, default to be 120
     * seconds if not specified by the caller.
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NotSupportedError} Thrown when the operation is not supported.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.InvalidArgumentError} Thrown when an invalid argument is provided.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async setLocalDeviceVisibility(protocol, visibility, duration) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.setLocalDeviceVisibility(protocol, visibility, duration === undefined ? DEFAULT_VISIBLE_DURATION : duration);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Start accessory autopair.
     *
     * @privilege com.amazon.acc.privilege.pair
     *
     * @param[in] protocol Accessory protocol to start autopair
     * @param[in] category Accessory category
     * @param[in] duration Accessory autopair duration in seconds, default to be 120 seconds if not
     * specified by the caller.
     *
     * @remarks This is specially used to automatically discover and pair with Remote Controllers
     * in TV use cases, only AccessoryProtocol.BLUTOOTH & AccessoryCategory.REMOTE_CONTROLLER
     * is supported currently. It may be enhanced to support other use cases in future release.
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.InProgressError} Thrown when the operation is already in progress.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NotSupportedError} Thrown when the operation is not supported.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async startAccessoryAutopair(protocol, category, duration) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.startAccessoryAutopair(protocol, category, duration === undefined ? DEFAULT_AUTO_PAIR_DURATION : duration);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Cancel accessory autopair
     *
     * @privilege com.amazon.acc.privilege.pair
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async cancelAccessoryAutopair(protocol) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.cancelAccessoryAutopair(protocol);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Pair accessory
     *
     * @privilege com.amazon.acc.privilege.pair
     *
     * @param[in] accessoryIdentity Accessory identity to pair
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async pairAccessory(accessoryIdentity) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.pairAccessory(accessoryIdentity);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Unpair accessory
     *
     * @privilege com.amazon.acc.privilege.pair
     *
     * @param[in] accessoryIdentity Accessory identity to unpair
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async unpairAccessory(accessoryIdentity) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.unpairAccessory(accessoryIdentity);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Connect accessory
     *
     * @privilege com.amazon.acc.privilege.connect
     *
     * @param[in] accessoryIdentity Accessory identity to connect
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async connectAccessory(accessoryIdentity) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.connectAccessory(accessoryIdentity);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Disconnect accessory
     *
     * @privilege com.amazon.acc.privilege.connect
     *
     * @param[in] accessoryIdentity Accessory identity to disconnect
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async disconnectAccessory(accessoryIdentity) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.disconnectAccessory(accessoryIdentity);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief start accessory DFU
     *
     * @privilege com.amazon.acc.privilege.control
     *
     * @param[in] accessoryIdentity Accessory identity to start DFU
     * @param[in] dfuMode Accessory DFU Type to be triggered
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotFoundError} Thrown when the requested accessory is not found.
     * @throws {AccClientErrors.NotSupportedError} Thrown when the operation is not supported.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async startAccessoryDfu(accessoryIdentity, dfuMode) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.startAccessoryDfu(accessoryIdentity, dfuMode);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Send accessory pairing response
     *
     * @privilege com.amazon.acc.privilege.pair
     *
     * @param[in] accessoryIdentity Accessory identity to send pairing response
     * @param[in] pairingResponse App provided pairing response
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.InvalidArgumentError} Thrown when an invalid argument is provided.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async sendAccessoryPairingResponse(accessoryIdentity, pairingResponse) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.sendAccessoryPairingResponse(accessoryIdentity, pairingResponse);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return AccClientTypes_1.AccessoryControlStatus.SUCCESS;
    }
    /**
     * @brief Get accessory list
     *
     * @privilege com.amazon.acc.privilege.access
     *
     * @param[in] accessoryList Accessory list type
     *
     * @returns {AccessoryListType} Accessory list
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async getAccessoryList(accessoryList) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.getAccessoryList(accessoryList);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return response.response;
    }
    /**
     * @brief Get accessory information
     *
     * @privilege com.amazon.acc.privilege.access
     *
     * @param[in] accessoryIdentity Accessory identity to get information
     * @param[in] needExtraInfo Boolean flag to get extra information, default as false.
     * @param[in] extraInfoKeys Array of extra information keys, valid when `needExtra` is true.
     *
     * @returns {AccessoryInfo} Accessory information
     *
     * @throws {AccClientErrors.TimeOutError} Thrown when the operation has timed out.
     * @throws {AccClientErrors.OutOfResourceError} Thrown when there are no available resources.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.NotConnectedError} Thrown when error occured in connection with server.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async getAccessoryInfo(accessoryIdentity, needExtraInfo, extraInfoKeys) {
        this.checkInitiazationState();
        const response = await AccClientTurboModule_1.default.getAccessoryInfo(accessoryIdentity, needExtraInfo === undefined ? false : needExtraInfo, extraInfoKeys === undefined ? [] : extraInfoKeys);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return response.response;
    }
    /**
     * @brief Get accessory configuration
     *
     * @privilege com.amazon.acc.privilege.restricted
     *
     * @param[in] accessoryIdentity Accessory identity
     *
     * @returns {AccessoryConfigurationEntry} Accessory configuration
     *
     * @throws {AccClientErrors.NotSupportedError} Thrown when the configuration interface is not supported.
     * @throws {AccClientErrors.NotFoundError} Thrown when there are no available configuration.
     * @throws {AccClientErrors.TryAgainError} Thrown when the application need to try again.
     * @throws {AccClientErrors.NoPermissionError} Thrown when the user or application lacks the necessary permissions.
     * @throws {AccClientErrors.AccessoryError} Thrown for any other unspecified error.
     */
    async getAccessoryConfiguration(accessoryIdentity) {
        const response = await AccClientTurboModule_1.default.getAccessoryConfiguration(accessoryIdentity);
        if (response.status !== AccClientTypes_1.AccessoryControlStatus.SUCCESS) {
            throwException(response.status);
        }
        return response.response;
    }
    clientEventDispatcher = (event) => {
        if (this.clientCallbacks === undefined) {
            return;
        }
        switch (event.dispatch) {
            case AccessoryControlEvent.DISCOVERY_STATE_CHANGED:
                {
                    if (this.clientCallbacks.onAccessoryDiscoveryStateChange !==
                        undefined &&
                        event.state !== undefined) {
                        this.clientCallbacks.onAccessoryDiscoveryStateChange(event.state);
                    }
                }
                break;
            case AccessoryControlEvent.AUTOPAIR_STATE_CHANGED:
                {
                    if (this.clientCallbacks.onAccessoryAutopairStateChange !== undefined &&
                        event.state !== undefined) {
                        this.clientCallbacks.onAccessoryAutopairStateChange(event.state);
                    }
                }
                break;
            case AccessoryControlEvent.PAIR_STATE_CHANGED:
                {
                    if (this.clientCallbacks.onAccessoryPairingStateChange !== undefined &&
                        event.basics !== undefined &&
                        event.state !== undefined) {
                        this.clientCallbacks.onAccessoryPairingStateChange(event.basics, event.state);
                    }
                }
                break;
            case AccessoryControlEvent.CONNECT_STATE_CHANGED:
                {
                    if (this.clientCallbacks.onAccessoryConnectionStateChange !==
                        undefined &&
                        event.basics !== undefined &&
                        event.state !== undefined) {
                        this.clientCallbacks.onAccessoryConnectionStateChange(event.basics, event.state);
                    }
                }
                break;
            case AccessoryControlEvent.ACCESSORY_DISCOVERED:
                {
                    if (this.clientCallbacks.onAccessoryDiscovery !== undefined &&
                        event.basics !== undefined) {
                        this.clientCallbacks.onAccessoryDiscovery(event.basics);
                    }
                }
                break;
            case AccessoryControlEvent.ACCESSORY_AUTOPAIRED:
                {
                    if (this.clientCallbacks.onAccessoryAutopair !== undefined &&
                        event.basics !== undefined) {
                        this.clientCallbacks.onAccessoryAutopair(event.basics);
                    }
                }
                break;
            case AccessoryControlEvent.PAIRING_REQUEST_RECEIVED:
                {
                    if (this.clientCallbacks.onAccessoryPairingRequest !== undefined &&
                        event.basics !== undefined &&
                        event.message !== undefined) {
                        const request = {
                            message: event.message,
                        };
                        this.clientCallbacks.onAccessoryPairingRequest(event.basics, request);
                    }
                }
                break;
            case AccessoryControlEvent.ACCESSORY_INFO_UPDATED:
                {
                    if (this.clientCallbacks.onAccessoryInfoUpdate !== undefined &&
                        event.basics !== undefined &&
                        event.extras !== undefined) {
                        this.clientCallbacks.onAccessoryInfoUpdate(event.basics, event.extras);
                    }
                }
                break;
            case AccessoryControlEvent.DFU_STATE_CHANGED:
                {
                    if (this.clientCallbacks.onAccessoryDfuStateChange !== undefined &&
                        event.basics !== undefined &&
                        event.state !== undefined) {
                        this.clientCallbacks.onAccessoryDfuStateChange(event.basics, event.state);
                    }
                }
                break;
            default:
                break;
        }
    };
}
exports.ConnectivityController = ConnectivityController;
