from lnx.logicnode.lnx_nodes import *


class WriteFileNode(LnxLogicTreeNode):
    """Writes the given string content to the given file. If the file
    already exists, the existing content of the file is overwritten.

    > **This node is currently only implemented on Krom**

    @input File: the name of the file, relative to `Krom.getFilesLocation()`
    @input Content: the content to write to the file.

    @seeNode Read File
    """
    bl_idname = 'LNWriteFileNode'
    bl_label = 'Write File'
    lnx_section = 'file'
    lnx_version = 2

    def lnx_init(self, context):
        self.add_input('LnxNodeSocketAction', 'In')
        self.add_input('LnxStringSocket', 'File')
        self.add_input('LnxStringSocket', 'Content')

        self.add_output('LnxNodeSocketAction', 'Out')

    def get_replacement_node(self, node_tree: bpy.types.NodeTree):
        if self.lnx_version not in (0, 1):
            raise LookupError()

        return NodeReplacement.Identity(self)