# legacy_test/core/model_loader.py
"""PPO model loader for legacy test scripts.

Wraps the reproduce ModelInventory to provide a simpler interface for
Track A test scripts that only need to load models onto CPU.
"""

from __future__ import annotations

import os
import sys
from typing import Optional

import numpy as np

_REPO = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."))
_SRC = os.path.join(_REPO, "src")
for p in [_REPO, _SRC]:
    if p not in sys.path:
        sys.path.insert(0, p)

from drl_pinball.reproduce.configs.model_inventory import ModelInventory  # noqa: E402

_inventory = ModelInventory()


def load_model(name: str) -> "PPO":
    """Load a PPO model onto CPU for inference.

    Returns a PPO model loaded from ``models/{subdir}/{name}.zip``
    with Sin activation and correct observation/action spaces.

    Delegates to ModelInventory.load(name, device="cpu").
    """
    return _inventory.load(name, device="cpu")


def list_models(scene: Optional[str] = None) -> list:
    """List available model names, optionally filtered by scene."""
    return _inventory.list_models(scene)
