/*
 * Copyright (C) 2025 Huawei Device 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 OHOS_3D_POSTPROCESS_ETS_H
#define OHOS_3D_POSTPROCESS_ETS_H

#include <meta/api/util.h>
#include <scene/interface/intf_postprocess.h>
#include <scene/interface/intf_camera.h>

#include "TonemapETS.h"
#include "BloomETS.h"
#include "VignetteETS.h"
#include "ColorFringeETS.h"

namespace OHOS::Render3D {
class PostProcessETS {
public:
    static std::shared_ptr<PostProcessETS> FromJS(const std::shared_ptr<TonemapETS> tonemap,
        const std::shared_ptr<BloomETS> bloom, const std::shared_ptr<VignetteETS> vignette,
        const std::shared_ptr<ColorFringeETS> colorFringe);
    PostProcessETS(const SCENE_NS::ICamera::Ptr camera, const SCENE_NS::IPostProcess::Ptr pp);
    // store post process settings from ETS
    PostProcessETS(const std::shared_ptr<TonemapETS> tonemap, const std::shared_ptr<BloomETS> bloom,
        const std::shared_ptr<VignetteETS> vignette, const std::shared_ptr<ColorFringeETS> colorFringe);
    ~PostProcessETS();

    std::shared_ptr<TonemapETS> GetToneMapping();
    void SetToneMapping(const std::shared_ptr<TonemapETS> tonemap);

    std::shared_ptr<BloomETS> GetBloom();
    void SetBloom(const std::shared_ptr<BloomETS> bloom);

    std::shared_ptr<VignetteETS> GetVignette();
    void SetVignette(const std::shared_ptr<VignetteETS> vignette);

    std::shared_ptr<ColorFringeETS> GetColorFringe();
    void SetColorFringe(const std::shared_ptr<ColorFringeETS> colorFringe);

    bool StrictEqual(const std::shared_ptr<PostProcessETS> other) const
    {
        if (!other) {
            return false;
        }
        auto myCamera = camera_.lock();
        auto otherCamera = other->camera_.lock();
        auto myPostProc = postProc_.lock();
        auto otherPostProc = other->postProc_.lock();

        if (!myCamera || !otherCamera || !myPostProc || !otherPostProc) {
            return false;
        }
        return (myCamera == otherCamera && myPostProc == otherPostProc);
    }

    bool IsMatch(const std::shared_ptr<PostProcessETS> other) const
    {
        // one postprocess cannot be assigned to different camera.
        if (!other) {
            return true;
        }
        auto otherCamera = other->camera_.lock();
        if (!otherCamera) {
            return true;
        }
        return camera_.lock() == otherCamera;
    }

private:
    SCENE_NS::ICamera::WeakPtr camera_{nullptr};  // weak ref to owning camera.
    SCENE_NS::IPostProcess::WeakPtr postProc_{nullptr};

    std::shared_ptr<TonemapETS> tonemap_;
    std::shared_ptr<BloomETS> bloom_;
    std::shared_ptr<VignetteETS> vignette_;
    std::shared_ptr<ColorFringeETS> colorFringe_;
};
}  // namespace OHOS::Render3D
#endif  // OHOS_3D_POSTPROCESS_ETS_H