namespace PkmnLib.Plugin.Gen7.Scripts.Utils;

public static class EnvironmentHelper
{
    public enum EnvironmentCategory
    {
        Electric,
        Fairy,
        Grass,
        Psychic,
        Rock,
        Ground,
        Ice,
        Water,
        Normal,
    }

    public static EnvironmentCategory GetEnvironmentCategory(this IBattle battle)
    {
        var terrainName = battle.TerrainName;
        if (terrainName == ScriptUtils.ResolveName<Terrain.ElectricTerrain>())
            return EnvironmentCategory.Electric;
        if (terrainName == ScriptUtils.ResolveName<Terrain.MistyTerrain>())
            return EnvironmentCategory.Fairy;
        if (terrainName == ScriptUtils.ResolveName<Terrain.GrassyTerrain>())
            return EnvironmentCategory.Grass;
        if (terrainName == ScriptUtils.ResolveName<Terrain.PsychicTerrain>())
            return EnvironmentCategory.Psychic;

        var environment = battle.EnvironmentName;
        if (environment.Contains("cave"))
            return EnvironmentCategory.Rock;
        if (environment.Contains("mountain") || environment.Contains("beach"))
            return EnvironmentCategory.Ground;
        if (environment.Contains("snow"))
            return EnvironmentCategory.Ice;
        if (environment.Contains("sea") || environment.Contains("lake") || environment.Contains("river"))
            return EnvironmentCategory.Water;
        if (environment.Contains("forest") || environment.Contains("field"))
            return EnvironmentCategory.Normal;
        return EnvironmentCategory.Normal; // Default case if no specific environment is matched
    }
}