package com.livingworld.events;

/**
 * Immutable base implementation of {@link LivingWorldEvent}.
 *
 * <p>This class provides a simple, validated event object that ecosystem modules
 * and other simulation components can instantiate directly. All fields are final
 * and the class is immutable after construction.</p>
 */
public final class BaseLivingWorldEvent implements LivingWorldEvent {

    private final String eventType;
    private final long simulationTick;
    private final String sourceModuleId;

    /**
     * Creates a new base living world event.
     *
     * @param eventType       the event type identifier (must not be null or blank)
     * @param simulationTick  the simulation tick at which this event occurred (must not be negative)
     * @param sourceModuleId  the module ID that generated this event (may be "core" for core events, must not be null or blank)
     * @throws IllegalArgumentException if any field violates validation rules
     */
    public BaseLivingWorldEvent(String eventType, long simulationTick, String sourceModuleId) {
        if (eventType == null || eventType.isBlank()) {
            throw new IllegalArgumentException("eventType must not be null or blank");
        }
        if (simulationTick < 0) {
            throw new IllegalArgumentException("simulationTick must not be negative");
        }
        if (sourceModuleId == null || sourceModuleId.isBlank()) {
            throw new IllegalArgumentException("sourceModuleId must not be null or blank");
        }

        this.eventType = eventType;
        this.simulationTick = simulationTick;
        this.sourceModuleId = sourceModuleId;
    }

    /**
     * Returns the event type identifier.
     *
     * @return the event type (never null or blank)
     */
    @Override
    public String eventType() {
        return eventType;
    }

    /**
     * Returns the simulation tick at which this event occurred.
     *
     * @return the simulation tick (never negative)
     */
    @Override
    public long simulationTick() {
        return simulationTick;
    }

    /**
     * Returns the module ID that generated this event.
     *
     * @return the source module ID (may be "core" for core-generated events, never null or blank)
     */
    @Override
    public String sourceModuleId() {
        return sourceModuleId;
    }

    /**
     * Returns a string representation of this event.
     *
     * @return a formatted string with eventType, simulationTick, and sourceModuleId
     */
    @Override
    public String toString() {
        return "BaseLivingWorldEvent{eventType='" + eventType + "', simulationTick=" + simulationTick +
                ", sourceModuleId='" + sourceModuleId + "'}";
    }
}