// Copyright (c) 2023 Codemongous LLC. All Rights Reserved.

#pragma once

#include "SourcifyCoreDefines.h"
#include "UEHelpers/StringHelpers.h"
#include <string>

using std::wstring;

namespace Sourcify
{
    enum class NodeErrorStatus : uint8_t
	{
		None = 0,
		Warning,
		Fatal
	};

	
    // This struct is used to store the settings for the conversion process of a given asset (BP, Struct, Enum, or Interface)
    struct FConversionSettings
    {
        wstring OutputDirectory;
        wstring OutputFileName;
        wstring TypeName;
        wstring TypePrefix;
        wstring LastInputValidityErrorText;
        bool Resourcify = true;

        bool GetResourcify() const
        {
            return Resourcify;
        }

        void SetResourcify(bool InResourcify)
        {
            Resourcify = InResourcify;
            if (Resourcify)
            {
                RestoreResourcifySettings();
            }
        }

        void CacheResourcifySettings()
        {
            CachedOutputDirectory = OutputDirectory;
            CachedOutputFileName = OutputFileName;
            CachedTypeName = TypeName;
            CachedTypePrefix = TypePrefix;
        }

        void RestoreResourcifySettings()
        {
            OutputDirectory = CachedOutputDirectory;
            OutputFileName = CachedOutputFileName;
            TypeName = CachedTypeName;
            TypePrefix = CachedTypePrefix;
        }

        enum class ETypePrefix : uint8_t
        {
            Header,
			Source
        };
		wstring GetFullOutputPath(ETypePrefix Prefix) const
		{
			return OutputDirectory + L"/" + OutputFileName + (Prefix == ETypePrefix::Header ? L".h" : L".cpp");
		}

        wstring GetFullTypeName() const
        {
            return TypePrefix + TypeName;
        }

        void CopyFrom(const FConversionSettings& Other, bool IgnoreCache = false)
        {
	        if (!IgnoreCache)
	        {
                *this = Other;
	        }
            else
            {
				OutputDirectory = Other.OutputDirectory;
				OutputFileName = Other.OutputFileName;
				TypeName = Other.TypeName;
				TypePrefix = Other.TypePrefix;
		        LastInputValidityErrorText = Other.LastInputValidityErrorText;
		        Resourcify = Other.Resourcify;
            }
        }

        SOURCIFY_CORE_DLL bool IsDirectoryInAnyModule() const;
        SOURCIFY_CORE_DLL void PopulateFromClassName(const wstring& Name);

        
    private:
        
        wstring CachedOutputDirectory;
        wstring CachedOutputFileName;
        wstring CachedTypeName;
        wstring CachedTypePrefix;
    };
}