from .._omni_kit_usd_layers import LayerEditMode
from .layers_state import LayersState
from .specs_locking import SpecsLocking
from .auto_authoring import AutoAuthoring
from .specs_linking import SpecsLinking
from .live_syncing import LiveSyncing


class Layers:
    def __init__(self, layers_instance, usd_context) -> None:
        self._layers_instance = layers_instance
        self._usd_context = usd_context
        if self._layers_instance:
            self._layers_state = LayersState(layers_instance, usd_context)
            self._specs_locking = SpecsLocking(layers_instance, usd_context)
            self._auto_authoring = AutoAuthoring(layers_instance, usd_context)
            self._specs_linking = SpecsLinking(layers_instance, usd_context)
            self._live_syncing = LiveSyncing(layers_instance, usd_context, self._layers_state)
        else:
            self._layers_state = None
            self._specs_locking = None
            self._auto_authoring = None
            self._specs_linking = None
            self._live_syncing = None

    def destroy(self):
        if self._specs_locking:
            self._specs_locking.destroy()
            self._specs_locking = None
        if self._auto_authoring:
            self._auto_authoring.destroy()
            self._auto_authoring = None
        if self._specs_linking:
            self._specs_linking.destroy()
            self._specs_linking = None
        if self._live_syncing:
            self._live_syncing.stop_all_live_sessions()
            self._live_syncing.destroy()
            self._live_syncing = None
        if self._layers_state:
            self._layers_state.destroy()
            self._layers_state = None
        self._usd_context = None

    def get_layers_state(self) -> LayersState:
        return self._layers_state

    def get_specs_locking(self) -> SpecsLocking:
        return self._specs_locking

    def get_auto_authoring(self) -> AutoAuthoring:
        return self._auto_authoring

    def get_specs_linking(self) -> SpecsLinking:
        return self._specs_linking
    
    def get_live_syncing(self) -> LiveSyncing:
        return self._live_syncing

    def get_event_stream(self):
        return self._layers_instance.get_event_stream()

    def get_edit_mode(self) -> LayerEditMode:
        return self._layers_instance.get_edit_mode()

    def set_edit_mode(self, edit_mode: LayerEditMode):
        self._layers_instance.set_edit_mode(edit_mode)
    
    @property
    def usd_context(self):
        return self._usd_context


