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.math.vector.Transform;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;

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

public class HomeComponent implements Component<EntityStore> {
    public static final BuilderCodec<HomeComponent> CODEC;
    private Transform transform;
    private UUID worldUuid;

    public HomeComponent() {
    }

    public HomeComponent(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
    public Component<EntityStore> clone() {
        return new HomeComponent(this.transform != null ? this.transform.clone() : null, this.worldUuid);
    }

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