package leigh.minecraft.leighco;

import leigh.mecha.cli.CommandState;
import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;

import java.util.Objects;
import java.util.UUID;

public class LeighCoState implements CommandState {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(LeighCoState.class);
    private final String playerName;
    private final LeighCoApp app;
    private final Location location;
    private final UUID playerId;

    public LeighCoState(String playerName, LeighCoApp app, Location location, UUID playerId) {
        this.playerName = playerName;
        this.app = app;
        this.location = location;
        this.playerId = playerId;
    }

    public String getPlayerName() {
        return playerName;
    }

    public LeighCoApp getApp() {
        return app;
    }

    public UUID getPlayerId() {
        return playerId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        LeighCoState that = (LeighCoState) o;
        return Objects.equals(playerName, that.playerName) && Objects.equals(app, that.app) && Objects.equals(location, that.location) && Objects.equals(playerId, that.playerId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(playerName, app, location, playerId);
    }

    public Location getLocation() {
        return location;
    }

    @Override
    public String toString() {
        return "LeighCoState{" +
                "playerName='" + playerName + '\'' +
                ", app=" + app +
                ", location=" + location +
                ", playerId=" + playerId +
                '}';
    }

    @Override
    public void sendMessage(String msg) throws Exception {
        logger.info("Wanted to send msg: [p: {}] [msg: {}]", playerName, msg);
        app.sendMessage(playerName, "[LC] " + msg);
    }
}
