/*
 *    This file is a part of the SteamWar software.
 *
 *    Copyright (C) 2023  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 de.steamwar.core.BountifulWrapper;
import de.steamwar.core.Core;
import lombok.Getter;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;

import java.util.function.Consumer;

public class RArmorStand extends REntity {

    private static int sizeIndex() {
        switch(Core.getVersion()) {
            case 8:
            case 9:
                return 10;
            case 10:
            case 12:
                return 11;
            case 14:
                return 13;
            case 15:
                return 14;
            case 18:
            case 19:
            default:
                return 15;
        }
    }

    private static final Object sizeWatcher = BountifulWrapper.impl.getDataWatcherObject(sizeIndex(), Byte.class);

    @Getter
    private final Size size;

    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)
            packetSink.accept(getDataWatcherPacket(sizeWatcher, size.value));
    }

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

        private final byte value;

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