/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 SLE_HOST_H
#define SLE_HOST_H

#include <iostream>
#include <memory>
#include "sle_device_config.h"
#include "sle_common_config.h"
#include "sle_error_code.h"

namespace OHOS {
namespace NearLink {
namespace SleStandard {
class SleHostCallback {
public:
    /**
     *   @brief A destructor used to delete the <b>SleHostCallback</b> instance.
     */
    virtual ~SleHostCallback() = default;

    /**
     *   @brief   Host state change callback
     *
     *   @param   [in] state - host state
     *   @return  None
     */
    virtual void OnSleStateChange(SleDeviceState state) = 0;

    /**
     *   @brief   Flow Monitor event callback
     *
     *   @param   [in] flow - flow
     *   @return  SleErrorCode
     */
    virtual void OnFlowMonitorEvent(float flow) = 0;
};

class SleHost {
public:
    /**
     *   @brief   Get default host
     *
     *   @return  SleHost instance ptr
     */
    static SleHost &GetDefaultHost();

    /**
     *   @brief   Enable sle sync
     *
     *   @return  SleErrorCode
     */
    SleErrorCode EnableSle();

    /**
     *   @brief   Disable sle sync
     *
     *   @return  SleErrorCode
     */
    SleErrorCode DisableSle();

    /**
     *   @brief   Get sle state sync
     *
     *   @param   [out] state - sle state
     *   @return  SleErrorCode
     */
    SleErrorCode GetSleState(SleDeviceState &state);

    /**
     *   @brief   Get host address sync
     *   @param   [out] address - host address
     *   @return  SleErrorCode
     */
    SleErrorCode GetHostAddress(SleDeviceAddress &address);

    /**
     *   @brief   Set host name sync
     *
     *   @param   [in] name - host name
     *   @return  SleErrorCode
     */
    SleErrorCode SetHostName(const std::string name);

    /**
     *   @brief   Get host name sync
     *
     *   @param   [out] name - host name
     *   @return  SleErrorCode
     */
    SleErrorCode GetHostName(std::string &name);

    /**
     *   @brief   Start flow monitor sync
     *
     *   @return  SleErrorCode
     *
     *   @note Receive flow monitor event info in OnFlowMonitorEvent
     */
    SleErrorCode StartFlowMonitor();

    /**
     *   @brief   Stop flow monitor sync
     *
     *   @return  SleErrorCode
     */
    SleErrorCode StopFlowMonitor();

    /**
     *   @brief   get host device default connectConfig callback sync
     *
     *   @param   [out] hostConnParam - host default connect config
     *   @return  SleErrorCode
     */
    SleErrorCode GetHostDefaultConnectConfig(SleConnectConfig &hostConnParam);

    /**
     *   @brief   Registe host callback sync
     *
     *   @param   [in] callback - host callback
     *   @return  SleErrorCode
     */
    SleErrorCode RegisterHostCallback(std::shared_ptr<SleHostCallback> callback);

    /**
     *   @brief   Unregist host callback sync
     *
     *   @param   [in] callback - host callback
     *   @return  SleErrorCode
     */
    SleErrorCode UnregisterHostCallback(std::shared_ptr<SleHostCallback> callback);

private:
    /**
     *   @brief A constructor used to create a <b>SleHost</b> instance.
     */
    SleHost();

    /**
     *   @brief A constructor used to delete a <b>SleHost</b> instance.
     */
    ~SleHost();

    class SleHostImpl;
    std::unique_ptr<SleHostImpl> pimpl_;

    SLE_DISALLOW_COPY_AND_ASSIGN(SleHost);
};
} // SleStandard
} // NearLink
} // OHOS

#endif // SLE_HOST_H