"""Operator for loading existing file into Rizom."""

import bpy
from bpy.types import Context

from rizomuvbridge_ultimate.functions.bpy_funcs.get_prefs import get_addon_prefs
from rizomuvbridge_ultimate.rizom.live_link.rizom_link import RizomInterface


class LoadInRizom(bpy.types.Operator):
    """Load the existing FBX/OBJ file into Rizom, no export."""

    bl_description = "Load the existing FBX/OBJ file into Rizom, no export"
    bl_idname = "ruv.rizom_load"
    bl_label = "Load (RizomUV)"
    bl_options = {"REGISTER", "INTERNAL"}

    def execute(self, context: Context) -> set[str]:
        """Execute the operator."""
        prefs = get_addon_prefs()
        interface = RizomInterface(prefs)

        interface.start()
        loaded, message = interface.load_file()
        if not loaded:
            self.report({"ERROR"}, message)
            return {"CANCELLED"}

        return {"FINISHED"}
