package com.livingworld.regions;

/**
 * Boolean flags that describe the current state of a region.
 *
 * <p>This class tracks transient and persistent conditions affecting a region,
 * such as player activity, pollution levels, soil quality, active ecosystem events,
 * simulation force-loading, and data corruption.</p>
 */
public class RegionFlags {

    private boolean hasPlayerActivity;
    private boolean hasHighPollution;
    private boolean hasLowSoilQuality;
    private boolean hasActiveEcosystemEvent;
    private boolean forceLoadedBySimulation;
    private boolean corrupted;

    /**
     * Default constructor. All flags are initialized to false.
     */
    public RegionFlags() {
        // all fields default to false
    }

    // ------------------------------------------------------------------
    // Getters and Setters
    // ------------------------------------------------------------------

    /**
     * Returns true if players have interacted with this region.
     */
    public boolean isHasPlayerActivity() {
        return hasPlayerActivity;
    }

    /**
     * Sets whether players have interacted with this region.
     */
    public void setHasPlayerActivity(boolean hasPlayerActivity) {
        this.hasPlayerActivity = hasPlayerActivity;
    }

    /**
     * Returns true if pollution levels in this region are high.
     */
    public boolean isHasHighPollution() {
        return hasHighPollution;
    }

    /**
     * Sets whether pollution levels are high.
     */
    public void setHasHighPollution(boolean hasHighPollution) {
        this.hasHighPollution = hasHighPollution;
    }

    /**
     * Returns true if soil quality in this region is low.
     */
    public boolean isHasLowSoilQuality() {
        return hasLowSoilQuality;
    }

    /**
     * Sets whether soil quality is low.
     */
    public void setHasLowSoilQuality(boolean hasLowSoilQuality) {
        this.hasLowSoilQuality = hasLowSoilQuality;
    }

    /**
     * Returns true if an active ecosystem event (fire, flood, etc.) is occurring.
     */
    public boolean isHasActiveEcosystemEvent() {
        return hasActiveEcosystemEvent;
    }

    /**
     * Sets whether an active ecosystem event is occurring.
     */
    public void setHasActiveEcosystemEvent(boolean hasActiveEcosystemEvent) {
        this.hasActiveEcosystemEvent = hasActiveEcosystemEvent;
    }

    /**
     * Returns true if the region is force-loaded by simulation and cannot be
     * unloaded by normal garbage collection.
     */
    public boolean isForceLoadedBySimulation() {
        return forceLoadedBySimulation;
    }

    /**
     * Sets whether the region is force-loaded by simulation.
     */
    public void setForceLoadedBySimulation(boolean forceLoadedBySimulation) {
        this.forceLoadedBySimulation = forceLoadedBySimulation;
    }

    /**
     * Returns true if this region has corrupted or inconsistent data.
     */
    public boolean isCorrupted() {
        return corrupted;
    }

    /**
     * Sets whether this region is corrupted.
     */
    public void setCorrupted(boolean corrupted) {
        this.corrupted = corrupted;
    }

    // ------------------------------------------------------------------
    // Copy and Clear
    // ------------------------------------------------------------------

    /**
     * Returns a new {@link RegionFlags} instance with identical field values.
     *
     * <p>The returned instance is independent; modifying it will not affect
     * the original flags.</p>
     */
    public RegionFlags copy() {
        RegionFlags copy = new RegionFlags();
        copy.hasPlayerActivity = this.hasPlayerActivity;
        copy.hasHighPollution = this.hasHighPollution;
        copy.hasLowSoilQuality = this.hasLowSoilQuality;
        copy.hasActiveEcosystemEvent = this.hasActiveEcosystemEvent;
        copy.forceLoadedBySimulation = this.forceLoadedBySimulation;
        copy.corrupted = this.corrupted;
        return copy;
    }

    /**
     * Clears transient flags: {@code hasPlayerActivity} and {@code hasActiveEcosystemEvent}.
     *
     * <p>Persistent flags such as {@code corrupted}, {@code hasHighPollution},
     * {@code hasLowSoilQuality}, and {@code forceLoadedBySimulation} are preserved.</p>
     */
    public void clearTransientFlags() {
        this.hasPlayerActivity = false;
        this.hasActiveEcosystemEvent = false;
    }

    // ------------------------------------------------------------------
    // Standard overrides
    // ------------------------------------------------------------------

    @Override
    public String toString() {
        return "RegionFlags{"
                + "hasPlayerActivity=" + hasPlayerActivity
                + ", hasHighPollution=" + hasHighPollution
                + ", hasLowSoilQuality=" + hasLowSoilQuality
                + ", hasActiveEcosystemEvent=" + hasActiveEcosystemEvent
                + ", forceLoadedBySimulation=" + forceLoadedBySimulation
                + ", corrupted=" + corrupted
                + "}";
    }
}