/*
 *
 *    Copyright (c) 2020-2021 Project CHIP Authors
 *
 *    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.
 */
#pragma once

#include <app/BufferedReadCallback.h>
#include <app/CommandSender.h>
#include <app/ReadClient.h>
#include <app/WriteClient.h>
#include <controller/CHIPDeviceController.h>
#include <jni.h>
#include <lib/core/CHIPError.h>
#include <lib/support/JniTypeWrappers.h>
#include <list>
#include <unordered_map>
#include <utility>

namespace chip {
namespace Controller {

CHIP_ERROR CreateChipAttributePath(JNIEnv * env, const app::ConcreteDataAttributePath & aPath, jobject & outObj);

// Callback for success and failure cases of GetConnectedDevice().
struct GetConnectedDeviceCallback
{
    GetConnectedDeviceCallback(
        jobject wrapperCallback, jobject javaCallback,
        const char * callbackClassSignature = "chip/devicecontroller/GetConnectedDeviceCallbackJni$GetConnectedDeviceCallback");
    ~GetConnectedDeviceCallback();

    static void OnDeviceConnectedFn(void * context, Messaging::ExchangeManager & exchangeMgr, const SessionHandle & sessionHandle);
    static void OnDeviceConnectionFailureFn(void * context, const OperationalSessionSetup::ConnectionFailureInfo & failureInfo);

    Callback::Callback<OnDeviceConnected> mOnSuccess;
    Callback::Callback<OperationalSessionSetup::OnSetupFailure> mOnFailure;
    JniGlobalReference mWrapperCallbackRef;
    JniGlobalReference mJavaCallbackRef;

private:
    const char * mCallbackClassSignature = nullptr;
};

struct ReportCallback : public app::ClusterStateCache::Callback
{
    /** Subscription established callback can be nullptr. */
    ReportCallback(jobject wrapperCallback, jobject subscriptionEstablishedCallback, jobject resubscriptionAttemptCallback,
                   const char * nodeStateClassSignature);
    ~ReportCallback();

    void OnReportBegin() override;

    void OnReportEnd() override;

    void OnAttributeData(const app::ConcreteDataAttributePath & aPath, TLV::TLVReader * apData,
                         const app::StatusIB & aStatus) override;
    void OnEventData(const app::EventHeader & aEventHeader, TLV::TLVReader * apData, const app::StatusIB * apStatus) override;

    void OnError(CHIP_ERROR aError) override;

    void OnDone(app::ReadClient *) override;

    void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override;

    CHIP_ERROR OnResubscriptionNeeded(app::ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override;

    void OnDeallocatePaths(app::ReadPrepareParams && aReadPrepareParams) override;

    /** Report errors back to Java layer. attributePath may be nullptr for general errors. */
    void ReportError(const app::ConcreteAttributePath * attributePath, const app::ConcreteEventPath * eventPath, CHIP_ERROR err);
    void ReportError(const app::ConcreteAttributePath * attributePath, const app::ConcreteEventPath * eventPath,
                     Protocols::InteractionModel::Status status);
    void ReportError(const app::ConcreteAttributePath * attributePath, const app::ConcreteEventPath * eventPath,
                     const char * message, ChipError::StorageType errorCode);

    void UpdateClusterDataVersion();

    app::ReadClient * mReadClient = nullptr;

    app::ClusterStateCache mClusterCacheAdapter;
    JniGlobalReference mWrapperCallbackRef;
    JniGlobalReference mSubscriptionEstablishedCallbackRef;
    JniGlobalReference mResubscriptionAttemptCallbackRef;

    const char * mNodeStateClassSignature;
};

struct WriteAttributesCallback : public app::WriteClient::Callback
{
    WriteAttributesCallback(jobject wrapperCallback);
    ~WriteAttributesCallback();
    app::WriteClient::Callback * GetChunkedWriteCallback() { return &mChunkedWriteCallback; }

    void OnResponse(const app::WriteClient * apWriteClient, const app::ConcreteDataAttributePath & aPath,
                    app::StatusIB aStatus) override;
    /** Report errors back to Java layer. attributePath may be nullptr for general errors. */
    void OnError(const app::WriteClient * apWriteClient, CHIP_ERROR aProtocolError) override;

    void OnDone(app::WriteClient * apWriteClient) override;

    void ReportError(const app::ConcreteAttributePath * attributePath, CHIP_ERROR err);
    void ReportError(const app::ConcreteAttributePath * attributePath, Protocols::InteractionModel::Status status);
    void ReportError(const app::ConcreteAttributePath * attributePath, const char * message, ChipError::StorageType errorCode);

    app::WriteClient * mWriteClient = nullptr;
    app::ChunkedWriteCallback mChunkedWriteCallback;
    JniGlobalReference mWrapperCallbackRef;
};

struct InvokeCallback : public app::CommandSender::Callback
{
    InvokeCallback(jobject wrapperCallback);
    ~InvokeCallback();

    void OnResponse(app::CommandSender * apCommandSender, const app::ConcreteCommandPath & aPath, const app::StatusIB & aStatusIB,
                    TLV::TLVReader * apData) override;
    /** Report errors back to Java layer. attributePath may be nullptr for general errors. */
    void OnError(const app::CommandSender * apCommandSender, CHIP_ERROR aError) override;

    void OnDone(app::CommandSender * apCommandSender) override;

    void ReportError(CHIP_ERROR err);
    void ReportError(Protocols::InteractionModel::Status status);
    void ReportError(const char * message, ChipError::StorageType errorCode);

    app::CommandSender * mCommandSender = nullptr;
    JniGlobalReference mWrapperCallbackRef;
};

struct ExtendableInvokeCallback : public app::CommandSender::ExtendableCallback
{
    ExtendableInvokeCallback(jobject wrapperCallback);
    ~ExtendableInvokeCallback();

    void OnResponse(app::CommandSender * commandSender, const app::CommandSender::ResponseData & aResponseData) override;
    void OnNoResponse(app::CommandSender * commandSender, const app::CommandSender::NoResponseData & aNoResponseData) override;
    void OnError(const app::CommandSender * apCommandSender, const app::CommandSender::ErrorData & aErrorData) override;
    void OnDone(app::CommandSender * apCommandSender) override;

    app::CommandSender * mCommandSender = nullptr;
    JniGlobalReference mWrapperCallbackRef;
};

jlong newConnectedDeviceCallback(JNIEnv * env, jobject self, jobject callback);
void deleteConnectedDeviceCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newReportCallback(JNIEnv * env, jobject self, jobject subscriptionEstablishedCallbackJava,
                        jobject resubscriptionAttemptCallbackJava, const char * nodeStateClassSignature);
void deleteReportCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newWriteAttributesCallback(JNIEnv * env, jobject self);
void deleteWriteAttributesCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newInvokeCallback(JNIEnv * env, jobject self);
void deleteInvokeCallback(JNIEnv * env, jobject self, jlong callbackHandle);
jlong newExtendableInvokeCallback(JNIEnv * env, jobject self);
void deleteExtendableInvokeCallback(JNIEnv * env, jobject self, jlong callbackHandle);

} // namespace Controller
} // namespace chip
