package com.tiedup.remake.util;

import java.util.Optional;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.Nullable;

/**
 * Player type validation helpers.
 *
 * Provides methods for checking player side (client/server) and type casting.
 *
 * For kidnapped/bondage state checks, use {@link KidnappedHelper} directly.
 */
public final class ValidationHelper {

    private ValidationHelper() {}

    /**
     * Check if the player is a server-side ServerPlayer.
     *
     * @param player The player to check
     * @return true if player is non-null, server-side, and ServerPlayer instance
     */
    public static boolean isServerPlayer(@Nullable Player player) {
        return (
            player != null &&
            !player.level().isClientSide &&
            player instanceof ServerPlayer
        );
    }

    /**
     * Get the player as ServerPlayer if it's server-side.
     *
     * @param player The player to check
     * @return Optional containing ServerPlayer, or empty if not server-side
     */
    public static Optional<ServerPlayer> asServerPlayer(
        @Nullable Player player
    ) {
        if (isServerPlayer(player)) {
            return Optional.of((ServerPlayer) player);
        }
        return Optional.empty();
    }

    /**
     * Check if the player is client-side.
     *
     * @param player The player to check
     * @return true if player is non-null and on client side
     */
    public static boolean isClientSide(@Nullable Player player) {
        return player != null && player.level().isClientSide;
    }

    /**
     * Check if we're on the server side for this player.
     *
     * @param player The player to check
     * @return true if player is non-null and on server side
     */
    public static boolean isServerSide(@Nullable Player player) {
        return player != null && !player.level().isClientSide;
    }
}
