"""Tests for environment registration and package initialization."""

import gymnasium as gym
import pytest

import nephrosim


class TestRegistration:
    def test_version_string(self):
        assert nephrosim.__version__ == "0.1.0"

    def test_urea_clearing_registered(self):
        env = gym.make("nephrosim/UreaClearing-v0")
        assert env is not None
        env.close()

    def test_ultrafiltration_control_registered(self):
        env = gym.make("nephrosim/UltrafiltrationControl-v0")
        assert env is not None
        env.close()

    def test_phosphate_mgmt_registered(self):
        env = gym.make("nephrosim/PhosphateMgmt-v0")
        assert env is not None
        env.close()

    def test_full_dialysis_session_registered(self):
        env = gym.make("nephrosim/FullDialysisSession-v0")
        assert env is not None
        env.close()

    def test_nonexistent_env_raises(self):
        with pytest.raises(gym.error.NameNotFound):
            gym.make("nephrosim/Nonexistent-v0")

    def test_all_envs_have_observation_space(self):
        env_ids = [
            "nephrosim/UreaClearing-v0",
            "nephrosim/UltrafiltrationControl-v0",
            "nephrosim/PhosphateMgmt-v0",
            "nephrosim/FullDialysisSession-v0",
        ]
        for env_id in env_ids:
            env = gym.make(env_id)
            assert env.observation_space is not None
            assert env.action_space is not None
            env.close()

    def test_all_envs_reset_and_step(self):
        env_ids = [
            "nephrosim/UreaClearing-v0",
            "nephrosim/UltrafiltrationControl-v0",
            "nephrosim/PhosphateMgmt-v0",
            "nephrosim/FullDialysisSession-v0",
        ]
        for env_id in env_ids:
            env = gym.make(env_id)
            obs, info = env.reset(seed=42)
            assert obs is not None
            action = env.action_space.sample()
            obs2, reward, terminated, truncated, info = env.step(action)
            assert obs2 is not None
            env.close()
