/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.entity;

import lombok.Getter;
import lombok.Setter;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;

import java.util.function.Consumer;

@Getter
public class RArmorStand extends REntity implements RInteractableEntity<RArmorStand> {

    private static final EntityDataAccessor<Byte> sizeWatcher = new EntityDataAccessor<>(15, EntityDataSerializers.BYTE);

    private final Size size;

    @Setter
    private REntityActionListener<RArmorStand> callback = null;

    public RArmorStand(REntityServer server, Location location, Size size) {
        super(server, EntityType.ARMOR_STAND, location, 0);
        this.size = size;
        server.addEntity(this);
    }

    @Override
    void spawn(Consumer<Object> packetSink) {
        super.spawn(packetSink);

        if (size != null && size != Size.NORMAL) {
            entityDataPacket().add(sizeWatcher, size.value).send(packetSink);
        }
    }

    public enum Size {
        NORMAL((byte) 0x00),
        SMALL((byte) 0x01),
        MARKER((byte) 0x10);

        private final byte value;

        Size(byte value) {
            this.value = value;
        }
    }
}
