from __future__ import annotations

import logging
import sys
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from qgis.gui import QgisInterface

# Add local deps folder (needed for deps installation during development)
# to path before other imports
_deps_dir = Path(__file__).parent / "deps"
if str(_deps_dir) not in sys.path:
    sys.path.insert(0, str(_deps_dir))

# Add plugin dir so bare imports (e.g. `from domain_types import ...`) resolve
# when QGIS loads the plugin as a package
_plugin_dir = str(Path(__file__).resolve().parent)
if _plugin_dir not in sys.path:
    sys.path.insert(0, _plugin_dir)

# samgis_core + sam2_onnx: pre-bundled in deps/ via install_deps.sh / build_plugin.sh
# onnxruntime: installed at runtime via pip on first inference (non-blocking)

from .main import SamgisPlugin  # noqa: E402 — must be after sys.path setup

# Override log level for plugin + sam2_onnx namespaces (DEBUG aids bug reports;
# log rotation mitigates size). Root logger stays at INFO via setup_logging().
logging.getLogger("samgis").setLevel(logging.DEBUG)
logging.getLogger("sam2_onnx").setLevel(logging.DEBUG)


def classFactory(iface: QgisInterface) -> SamgisPlugin:
    return SamgisPlugin(iface)
