////////////////////////////////////////
// Programming project code
// UniBw M, 2022, 2023, 2024
// www.unibw.de/inf2
// (c) Mark Minas (mark.minas@unibw.de)
////////////////////////////////////////

package pp.monopoly.game.client;
import pp.monopoly.model.IntPoint;

import java.io.File;
import java.io.IOException;
import java.lang.System.Logger.Level;

/**
 * Defines the behavior and state transitions for the client-side game logic.
 * Different states of the game logic implement this interface to handle various game events and actions.
 */
abstract class ClientState {
    /**
     * The game logic object.
     */
    final ClientGameLogic logic;

    /**
     * Constructs a client state of the specified game logic.
     *
     * @param logic the game logic
     */
    ClientState(ClientGameLogic logic) {
        this.logic = logic;
    }

    /**
     * Method to be overridden by subclasses for post-transition initialization.
     * By default, it does nothing, but it can be overridden in derived states.
     */
    void entry() {
        // Default implementation does nothing
    }

    /**
     * Returns the name of the current state.
     *
     * @return the name of the current state
     */
    String getName() {
        return getClass().getSimpleName();
    }

    /**
     * Checks if the battle state should be shown.
     *
     * @return true if the battle state should be shown, false otherwise
     */
    boolean showTurn() {
        return false;
    }

    /**
     * Moves the preview figure to the specified position.
     *
     * @param pos the new position for the preview figure
     */
    void movePreview(IntPoint pos) {
        ClientGameLogic.LOGGER.log(Level.DEBUG, "movePreview has no effect in {0}", getName()); //NON-NLS
    }

    /**
     * Loads a map from the specified file.
     *
     * @param file the file to load the map from
     * @throws IOException if the map cannot be loaded in the current state
     */
    void loadMap(File file) throws IOException {
        throw new IOException("You are not allowed to load a map in this state of the game");
    }

    /**
     * Called once per frame by the update loop if this state is active.
     *
     * @param delta time in seconds since the last update call
     */
    void update(float delta) { /* do nothing by default */ }
}
