package thb.jeanluc.adventure.model.item;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.experimental.SuperBuilder;
import thb.jeanluc.adventure.game.GameContext;

/**
 * Abstract base class for every interactive object in the world.
 * Concrete subclasses implement {@link #use(GameContext)} to provide
 * type-specific behaviour. Items are intentionally "dumb": they do not
 * know which room or inventory currently holds them.
 */
@Getter
@SuperBuilder
@RequiredArgsConstructor
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
        @JsonSubTypes.Type(value = ReadableItem.class, name = "readable"),
        @JsonSubTypes.Type(value = SwitchableItem.class, name = "switchable"),
        @JsonSubTypes.Type(value = PlainItem.class, name = "plain")
})
public abstract class Item {

    /** Unique identifier of this item, used for lookup and player input matching. */
    protected final String id;

    /** Human-readable display name shown to the player. */
    protected final String name;

    /** Long description shown by the {@code examine} command. */
    protected final String description;

    /** Whether this item can serve as a light source (when on, for switchables). */
    protected final boolean light;

    /**
     * Executes the item's primary action. Side effects (text output,
     * mutation of player state) flow through the given context.
     *
     * @param ctx active game context providing player, world, and IO
     */
    public abstract void use(GameContext ctx);
}
