"""Module for keeping track of operations performed by the addon.

Primarily for displaying to the user.

"""

from bpy.types import Object


class UVTransferTracker:
    """Log all operations that the addon performs.

    Used to output a report to the user after the addon is finished
    working.

    """

    def __init__(self):
        """Initialize tracker."""
        self.missing_objects: set[str] = set()
        self.missing_uvmaps: dict[Object, list[str]] = {}
        self.updated_uvmaps: dict[Object, list[str]] = {}
        self.invalid_geometry: set[Object] = set()

    def add_missing_objects(self, obj_names: list[str]):
        """Add expected object that is missing when compared to Rizom scene.

        Args:
        ----
            obj_names (list[str]): List of object names

        """
        self.missing_objects.update(obj_names)

    def add_missing_uvmap(self, uvmap_object: Object, uvmap: str):
        """Add UVMap present in Rizom import but not on Blender object.

        Args:
        ----
            obj (Object): Object that is missing a UVMap.
            uvmap (str): Name of the missing UVMap.

        """
        if uvmap_object not in self.missing_uvmaps:
            self.missing_uvmaps[uvmap_object] = []
        self.missing_uvmaps[uvmap_object].append(uvmap)

    def add_updated_uvmap(self, obj: Object, uvmap: str):
        """Add UVMap that was successfully updated."""
        if obj not in self.updated_uvmaps:
            self.updated_uvmaps[obj] = []
        self.updated_uvmaps[obj].append(uvmap)

    def add_invalid_geometry(self, invalid_object: Object):
        """Add object that does not have equal polycount to it's Rizom counterpart.

        Args:
        ----
            obj (Object): Object that does not have equal polycount to it's Rizom counterpart.

        """
        self.invalid_geometry.add(invalid_object)

    def __str__(self):
        """Override class print output."""
        return (
            f"UV Transfer Tracker:\n"
            f"Missing objects: {self.missing_objects}\n"
            f"Missing UVMaps: {self.missing_uvmaps}\n"
            f"Updated UVMaps: {self.updated_uvmaps}\n"
            f"Invalid Geometry: {self.invalid_geometry}"
        )
