package net.miarma.hystuff.component;

import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.component.Component;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.math.vector.Transform;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

import javax.annotation.Nonnull;
import java.util.UUID;

public class LastPositionComponent implements Component<EntityStore> {

    public static final BuilderCodec<LastPositionComponent> CODEC;

    private Transform transform;
    private UUID worldUuid;

    public LastPositionComponent() {
    }

    public LastPositionComponent(Transform transform, UUID worldUuid) {
        this.transform = transform;
        this.worldUuid = worldUuid;
    }

    public Transform getTransform() {
        return this.transform;
    }

    public void setTransform(Transform transform) {
        this.transform = transform;
    }

    public UUID getWorldUuid() {
        return this.worldUuid;
    }

    public void setWorldUuid(UUID worldUuid) {
        this.worldUuid = worldUuid;
    }

    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        return new LastPositionComponent(
                this.transform != null ? this.transform.clone() : null,
                this.worldUuid
        );
    }

    static {
        CODEC = BuilderCodec.builder(LastPositionComponent.class, LastPositionComponent::new)
                .append(
                        new KeyedCodec<>("Transform", Transform.CODEC),
                        LastPositionComponent::setTransform,
                        LastPositionComponent::getTransform
                ).add()
                .append(
                        new KeyedCodec<>("WorldUuid", Codec.UUID_BINARY),
                        LastPositionComponent::setWorldUuid,
                        LastPositionComponent::getWorldUuid
                )
                .add()
                .build();
    }
}

