package com.livingworld.commands;

import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import com.livingworld.regions.Region;
import com.livingworld.regions.RegionFlags;
import com.livingworld.regions.RegionMetrics;

/**
 * Formats region diagnostics without depending on Minecraft classes.
 */
public final class RegionInfoFormatter {

    private RegionInfoFormatter() {
    }

    public static List<String> format(Region region) {
        if (region == null) {
            throw new IllegalArgumentException("region must not be null");
        }

        RegionMetrics metrics = region.getMetrics();
        RegionFlags flags = region.getFlags();
        Set<String> moduleIds = new TreeSet<>(region.getModuleData().moduleIds());

        return List.of(
                "Region: " + region.getCoordinate().stableId(),
                "Lifecycle: " + region.getLifecycleState() + ", dirty=" + region.isDirty(),
                "Metrics: ecosystemHealth=" + metrics.getEcosystemHealth()
                        + ", pollution=" + metrics.getPollutionScore()
                        + ", soilQuality=" + metrics.getSoilQuality()
                        + ", waterQuality=" + metrics.getWaterQuality()
                        + ", vegetationPressure=" + metrics.getVegetationPressure()
                        + ", resourceDepletion=" + metrics.getResourceDepletion()
                        + ", recoveryPressure=" + metrics.getRecoveryPressure(),
                "Flags: playerActivity=" + flags.isHasPlayerActivity()
                        + ", highPollution=" + flags.isHasHighPollution()
                        + ", lowSoilQuality=" + flags.isHasLowSoilQuality()
                        + ", activeEcosystemEvent=" + flags.isHasActiveEcosystemEvent()
                        + ", forceLoaded=" + flags.isForceLoadedBySimulation()
                        + ", corrupted=" + flags.isCorrupted(),
                "Module data: " + (moduleIds.isEmpty() ? "none" : String.join(", ", moduleIds)));
    }
}
