# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

import gymnasium as gym

from . import agents

##
# Register Gym environments.
##


gym.register(
    id="{{ task.id }}",
{% if task.workflow.name == "direct" or task.amp_selected %}
    entry_point=f"{__name__}.{{ task.env_filename }}:{{ task.classname }}Env",
{% else %}
    entry_point="isaaclab.envs:ManagerBasedRLEnv",
{% endif %}
    disable_env_checker=True,
    kwargs={
        "env_cfg_entry_point": f"{__name__}.{{ task.env_cfg_filename }}:{{ task.classname }}EnvCfg",
{% if rl_libraries | length == 1 %}
        "default_agent": "{{ rl_libraries[0].name }}",
{% endif %}
{# RL libraries configurations #}
{% for rl_library in rl_libraries %}
  {% for algorithm in rl_library.algorithms %}
    {# configuration file #}
    {% if rl_library.name == "rsl_rl" %}
      {% set runner_prefix = {"distillation": "Distillation"}.get(algorithm, algorithm|upper) %}
      {% set agent_config = "." ~ rl_library.name ~ "_" ~ algorithm ~ "_cfg:" ~ runner_prefix ~ "RunnerCfg" %}
    {% else %}
      {% set agent_config = ":" ~ rl_library.name ~ "_" ~ algorithm ~ "_cfg.yaml" %}
    {% endif %}
    {# canonical library configuration #}
    {% if algorithm == rl_library.canonical_algorithm %}
        "{{ rl_library.name }}_cfg_entry_point": f"{agents.__name__}{{ agent_config }}",
    {% endif %}
    {# explicit non-PPO algorithm configuration #}
    {% if algorithm != "ppo" %}
        "{{ rl_library.name }}_{{ algorithm }}_cfg_entry_point": f"{agents.__name__}{{ agent_config }}",
    {% endif %}
  {% endfor %}
{% endfor %}
    },
)
