/* SPDX-License-Identifier: BSD-3-Clause */
/*
 * Copyright 2020 Raritan Inc. All rights reserved.
 */

#ifndef __ZIGBEEMANAGER_IDL__
#define __ZIGBEEMANAGER_IDL__

#include <Event.idl>
#include <ZigbeeDevice.idl>

/** Zigbee */
module zigbee {
    /** Zigbee Manager */
    interface ZigbeeManager {

        /** Error Codes */
        constant int ERR_DEVICE_EXISTS = 1;
        constant int ERR_MAX_DEVICE_REACHED = 2;
        constant int ERR_DEVICE_NOT_FOUND = 3;
        constant int ERR_INVALID_PARAMS = 4;
        constant int ERR_INVALID_KEY = 5;
        constant int ERR_INVALID_CHANNEL = 6;

        /** States for the dongle */
        enumeration DongleState {
            NOT_INIT, ///< no dongle
            READY,  ///< default state if no action in progress
            ERROR,  ///< something wrong
            INIT_IN_PROGRESS, ///< dongle init in progress
            FW_UPGRADE, ///< firmware upgrade
            IN_MODEM_STATE ///< receiving state for fw update
        };

        /** Dongle MetaData*/
        structure MetaData {
            string firmwareVersion;                     ///< the current firmware version
            string stackVersion;                        ///< the current stack version
        };

        structure Settings {
            int channel;                        ///< channel between 11 and 26 or 0xFF for auto search
        };

        /** Device Registration */
        structure DeviceRegistration {
            int sourceId;                       ///< the source id to add
            string key;                         ///< the OOB key (including CRC16)
            int slot;                           ///< the preferred slot. 0xFFFF for auto manage
        };

        /** Base Event */
        valueobject DeviceEvent extends idl.Event {
            int sourceId;                       ///< the device which is affected by the event
        };

        /** A sensor was added */
        valueobject DeviceAddedEvent extends DeviceEvent {};

        /** A sensor was removed */
        valueobject DeviceRemovedEvent extends DeviceEvent {};

        /** Settings changed */
        valueobject SettingsChangedEvent extends idl.Event {
            Settings oldSettings;               ///< the old settings
            Settings newSettings;               ///< the new settings
        };

        /** State changed */
        valueobject StateChangedEvent extends idl.Event {
            DongleState oldState;               ///< the old state
            DongleState newState;               ///< the new state
        };

        /**
         * Retrieve Dongle MetaData
         *
         * @return MetaData
         */
        MetaData getMetaData();

        /**
         * Retrieve Dongle State
         *
         * @return DongleState
         */
        DongleState getDongleState();

        /**
         * Retrieve Dongle Settings
         *
         * @return Settings
         */
        Settings getSettings();

        /**
         * Set Dongle Settings
         *
         * @return 0                 if OK
         * @return ERR_INVALID_CHANNEL if the channel is invalid
         * @return ERR_INVALID_PARAMS if any parameters are invalid
         */
        int setSettings(in Settings settings);

        /**
         * Add new devices
         *
         * Return codes:
         * 0                 if OK
         * ERR_DEVICE_EXISTS if device is already in list
         * ERR_MAX_DEVICE_REACHED if the max device limit reached
         * ERR_INVALID_KEY if the key is wrong
         * ERR_INVALID_PARAMS if the entered data is invalid
         * @return List of return codes for each device
         */
        vector<int> addDevices(in vector<DeviceRegistration> sensors);

        /**
         * Remove a device
         *
         * @return 0                 if OK
         * @return ERR_DEVICE_NOT_FOUND if device is not registered
         */
        int removeDevice(in int sourceId);

        /**
         * Get the list of registered devices
         *
         * @return List of all registered devices
         */
        vector<ZigbeeDevice> getRegisteredDevices();
    };

}

#endif /* __ZIGBEEMANAGER_IDL__ */

