/******************************************************************************
*	File		-	image.cpp
*	Author		-	Joey Pollack
*	Date		-	2022/11/28 (y/m/d)
*	Mod Date	-	2022/11/28 (y/m/d)
*	Description	-	The editor warpper for an Image asset
******************************************************************************/

#include "image.h"
#include <renderer/texture.h>
#include <utils/logger.h>
#include <editor/editor_helpers.h>

namespace lunarium { namespace editor {

    Image::Image()
        : EditorAsset(AssetType::EATYPE_IMAGE), mpImage(nullptr)
    {

    }

    
    lunarium::Texture* Image::GetImage() const
    {
        return mpImage;
    }

    
    bool Image::DrawProperties()
    {
        
        return false;
    }

    /////////////////////////////////////////////////////////////////////
    //				SERIALIZATION
    /////////////////////////////////////////////////////////////////////
    OpRes Image::LoadRawFile()
    {
        mpImage = FileLoaders::LoadImage(mAssetDir / GetFileLocation());
        mpImage->FlipVertically();
        if (!mpImage)
        {
            return OpRes::Fail("Could not load image file: %s", GetFileLocation().string().c_str());
        }
        
        return OpRes::OK();
    }

    OpRes Image::Serialize(nlohmann::ordered_json& node)
    {
        

        return OpRes::OK();
    }

    OpRes Image::Deserialize(nlohmann::ordered_json& node)
    {
        LoadRawFile();
        return OpRes::OK();
    }

    bool Image::IsValidNode(nlohmann::ordered_json& node)
    {
        return true;
    }

    nlohmann::ordered_json Image::AsJSON()
    {
        return nlohmann::ordered_json();
    }

}}