/*
 *
 *    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 <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::ConnnectionFailureInfo & 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;
};

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);

} // namespace Controller
} // namespace chip
