/******************************************************************************
*	File		-	script.h
*	Author		-	Joey Pollack
*	Date		-	2022/11/02 (y/m/d)
*	Mod Date	-	2022/11/02 (y/m/d)
*	Description	-	Editor asset for script files
******************************************************************************/

#include "script.h"

#include <editor/editor.h>
#include <editor/editor_helpers.h>
#include <utils/helpers.h>
#include <utils/logger.h>
#include <fstream>

namespace lunarium { namespace editor 
{
    Script::Script(std::filesystem::path file_location, std::filesystem::path asset_dir)
        : EditorAsset(AssetType::EATYPE_SCRIPT)
    {
        std::string full_path = (asset_dir / file_location).string();
        std::ofstream ofs(asset_dir / file_location);
        if (!ofs.is_open())
        {
            Logger::Warn(Editor::LogCat, "Could not create file \"%s\"", full_path.c_str());
        }

        ofs.close();
        ofs.clear();

        mLocation = file_location;
    }

    std::filesystem::path Script::GetScriptFile()
    {
        return GetFileLocation();
    }

    std::string Script::GetScript()
    {
        return File::ReadTextFile((mAssetDir / GetFileLocation()).string());
    }

    OpRes Script::LoadRawFile()
    {
        return OpRes::OK();
    }

    OpRes Script::Serialize(nlohmann::ordered_json& node)
    {
        return OpRes::OK();
    }

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

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

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

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