package com.tiedup.remake.network.action;

import com.tiedup.remake.network.base.AbstractProgressPacketWithRole;
import com.tiedup.remake.state.PlayerBindState;
import com.tiedup.remake.tasks.PlayerStateTask;
import java.util.function.BiConsumer;
import java.util.function.Function;
import net.minecraft.network.FriendlyByteBuf;

/**
 * Packet for synchronizing force feeding progress from server to client.
 *
 * Sent by server to update the client's feeding task progress.
 * Includes role info so the progress bar can show different text
 * for feeder vs target.
 */
public class PacketForceFeeding extends AbstractProgressPacketWithRole {

    public PacketForceFeeding(
        int stateInfo,
        int maxState,
        boolean isActiveRole,
        String otherEntityName
    ) {
        super(stateInfo, maxState, isActiveRole, otherEntityName);
    }

    public static PacketForceFeeding decode(FriendlyByteBuf buf) {
        RolePacketData data = decodeRoleFields(buf);
        return new PacketForceFeeding(
            data.stateInfo(),
            data.maxState(),
            data.isActiveRole(),
            data.otherEntityName()
        );
    }

    @Override
    protected Function<PlayerBindState, PlayerStateTask> getTaskGetter() {
        return state -> state.tasks().getClientFeedingTask();
    }

    @Override
    protected BiConsumer<PlayerBindState, PlayerStateTask> getTaskSetter() {
        return (state, task) -> state.tasks().setClientFeedingTask(task);
    }
}
