package com.openosrs.client.core;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

/**
 * GameNPC - Represents a non-player character in the game world.
 */
public class GameNPC {
    private final int index;
    private final int id;
    private final AtomicInteger x = new AtomicInteger();
    private final AtomicInteger y = new AtomicInteger();
    private final AtomicInteger plane = new AtomicInteger();
    
    private final AtomicInteger animationId = new AtomicInteger(-1);
    private final AtomicInteger graphicId = new AtomicInteger(-1);
    private final AtomicInteger orientation = new AtomicInteger(0);
    private final AtomicInteger hitpoints = new AtomicInteger(100);
    private final AtomicInteger maxHitpoints = new AtomicInteger(100);
    private final AtomicInteger combatLevel = new AtomicInteger(1);
    
    private final AtomicReference<String> name = new AtomicReference<>("");
    private final AtomicReference<String> examine = new AtomicReference<>("");
    private final AtomicReference<String> overheadText = new AtomicReference<>("");
    
    private final AtomicInteger interacting = new AtomicInteger(-1);
    private final AtomicInteger targetIndex = new AtomicInteger(-1);
    
    public GameNPC(int index, int id, int x, int y, int plane) {
        this.index = index;
        this.id = id;
        this.x.set(x);
        this.y.set(y);
        this.plane.set(plane);
    }
    
    public void tick() {
        // Update NPC state each game tick
        // This could include movement, combat timers, etc.
    }
    
    // Position methods
    public void setPosition(int x, int y) {
        this.x.set(x);
        this.y.set(y);
    }
    
    public void setPosition(int x, int y, int plane) {
        this.x.set(x);
        this.y.set(y);
        this.plane.set(plane);
    }
    
    public int getIndex() { return index; }
    public int getId() { return id; }
    public int getX() { return x.get(); }
    public int getY() { return y.get(); }
    public int getPlane() { return plane.get(); }
    
    // Animation and graphics
    public void setAnimation(int animationId) { this.animationId.set(animationId); }
    public void setGraphic(int graphicId) { this.graphicId.set(graphicId); }
    public void setOrientation(int orientation) { this.orientation.set(orientation); }
    
    public int getAnimationId() { return animationId.get(); }
    public int getGraphicId() { return graphicId.get(); }
    public int getOrientation() { return orientation.get(); }
    
    // Health and combat
    public void setHitpoints(int current, int max) {
        this.hitpoints.set(current);
        this.maxHitpoints.set(max);
    }
    
    public void setCombatLevel(int level) { this.combatLevel.set(level); }
    
    public int getHitpoints() { return hitpoints.get(); }
    public int getMaxHitpoints() { return maxHitpoints.get(); }
    public int getCombatLevel() { return combatLevel.get(); }
    
    // Text and interaction
    public void setName(String name) { this.name.set(name != null ? name : ""); }
    public void setExamine(String examine) { this.examine.set(examine != null ? examine : ""); }
    public void setOverheadText(String text) { this.overheadText.set(text != null ? text : ""); }
    
    public String getName() { return name.get(); }
    public String getExamine() { return examine.get(); }
    public String getOverheadText() { return overheadText.get(); }
    
    // Interaction
    public void setInteracting(int targetIndex) { this.interacting.set(targetIndex); }
    public void setTargetIndex(int targetIndex) { this.targetIndex.set(targetIndex); }
    
    public int getInteracting() { return interacting.get(); }
    public int getTargetIndex() { return targetIndex.get(); }
    
    @Override
    public String toString() {
        return String.format("NPC[%d] id=%d name='%s' pos=(%d,%d,%d)", 
            index, id, name.get(), x.get(), y.get(), plane.get());
    }
}