## Copyright (c) 2023, NVIDIA CORPORATION.  All rights reserved.
##
## NVIDIA CORPORATION and its licensors retain all intellectual property
## and proprietary rights in and to this software, related documentation
## and any modifications thereto.  Any use, reproduction, disclosure or
## distribution of this software and related documentation without an express
## license agreement from NVIDIA CORPORATION is strictly prohibited.
##

import carb
import omni.kit.commands
import omni.rtx.ovtextureconverter


class IssueTextureCompressionRequest(omni.kit.commands.Command):
    def __init__(
            self,
            **kwargs,
    ):
        # pull out the stage name to process from the entry
        # check for a couple different forms
        self._path = None
        for key in ["path", "texture_path"]:
            if key in kwargs:
                self._path = kwargs[key]
                break

        # standardize the path separator character
        self._path = self._path.replace("\\", "/") if self._path else None
        self._convert_iface = omni.rtx.ovtextureconverter.acquire_ovtextureconverter_interface()

    def do(self):
        if not self._path:
            carb.log_warn("'path' not valid")
            return False

        carb.log_info("Processing Texture: " + self._path)

        # This inserts an async request, but we can't yet "await" it.
        # TODO: May need to sleep after this?
        return self._convert_iface.compressFileOnly(str(self._path))

omni.kit.commands.register_all_commands_in_module(__name__)
