package cz.jzitnik.game.sprites;

import java.util.Optional;

import cz.jzitnik.tui.Sprite;

public class Water extends Sprite {
    public enum WaterState {
        FIRST, SECOND, THIRD, FOURTH, FIFTH;

        public static WaterState get(int x) {
            return switch (x) {
                case 5 -> FIRST;
                case 4 -> SECOND;
                case 3 -> THIRD;
                case 2 -> FOURTH;
                case 1 -> FIFTH;
                default -> throw new IllegalStateException("Unexpected value: " + x);
            };
        }
    }

    public Water() {
        loadResource("water.ans");
    }

    public String getSprite() {
        return getSprite(WaterState.FIRST);
    }

    public String getSprite(Enum e) {
        String[] resource = getResource().split("\n");

        int numberFormTop = switch (e) {
            case WaterState.FIRST -> 0;
            case WaterState.SECOND -> 5;
            case WaterState.THIRD -> 10;
            case WaterState.FOURTH -> 15;
            case WaterState.FIFTH -> 20;
            default -> throw new IllegalStateException("Unexpected value: " + e);
        };

        StringBuilder stringBuilder = new StringBuilder();

        for (int i = 0; i < 25; i++) {
            if (i < numberFormTop) {
                stringBuilder.append("\033[49m ".repeat(50));
            } else {
                stringBuilder.append(resource[i]);
            }
            stringBuilder.append("\n");
        }

        return stringBuilder.toString();
    }

    @Override
    public Optional<Class<WaterState>> getStates() {
        return Optional.of(Water.WaterState.class);
    }
}
