"""Random baseline agent for NephroSim environments."""

import gymnasium as gym
import numpy as np

import nephrosim  # noqa: F401


def evaluate_random(
    env_id: str,
    n_episodes: int = 50,
    seed: int = 42,
) -> dict:
    """Evaluate a random agent on the given environment.

    Args:
        env_id: Gymnasium environment ID.
        n_episodes: Number of evaluation episodes.
        seed: Random seed.

    Returns:
        Dict with mean_reward, std_reward, episode_rewards.
    """
    rng = np.random.default_rng(seed)
    episode_rewards = []

    for ep in range(n_episodes):
        env = gym.make(env_id)
        obs, _ = env.reset(seed=int(rng.integers(0, 2**31)))
        total_reward = 0.0
        done = False

        while not done:
            action = env.action_space.sample()
            obs, reward, terminated, truncated, info = env.step(action)
            total_reward += float(reward)
            done = terminated or truncated

        episode_rewards.append(total_reward)
        env.close()

    return {
        "mean_reward": float(np.mean(episode_rewards)),
        "std_reward": float(np.std(episode_rewards)),
        "episode_rewards": episode_rewards,
    }
