// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.teleport;

import com.hypixel.hytale.codec.function.BsonFunctionCodec;
import com.hypixel.hytale.codec.validation.LegacyValidator;
import com.hypixel.hytale.codec.validation.Validators;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import java.util.Map;
import org.bson.BsonValue;
import com.hypixel.hytale.server.core.universe.Universe;
import com.hypixel.hytale.server.core.modules.entity.teleport.Teleport;
import java.util.Objects;
import com.hypixel.hytale.server.core.universe.world.World;
import javax.annotation.Nonnull;
import java.time.Instant;
import javax.annotation.Nullable;
import com.hypixel.hytale.math.vector.Transform;
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
import com.hypixel.hytale.codec.Codec;

@Deprecated
public class Warp
{
    public static final Codec<Warp> CODEC;
    public static final ArrayCodec<Warp> ARRAY_CODEC;
    private String id;
    private String world;
    @Nullable
    private Transform transform;
    private String creator;
    private Instant creationDate;
    
    public Warp() {
    }
    
    public Warp(@Nonnull final Transform transform, @Nonnull final String id, @Nonnull final World world, @Nonnull final String creator, @Nonnull final Instant creationDate) {
        this.id = id;
        this.world = world.getName();
        this.transform = transform;
        this.creator = creator;
        this.creationDate = creationDate;
    }
    
    public String getId() {
        return this.id;
    }
    
    public String getWorld() {
        return this.world;
    }
    
    @Nullable
    public Transform getTransform() {
        return this.transform;
    }
    
    public String getCreator() {
        return this.creator;
    }
    
    public Instant getCreationDate() {
        return this.creationDate;
    }
    
    @Override
    public boolean equals(@Nullable final Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || this.getClass() != o.getClass()) {
            return false;
        }
        final Warp warp = (Warp)o;
        return Objects.equals(this.id, warp.id) && Objects.equals(this.world, warp.world) && Objects.equals(this.transform, warp.transform) && Objects.equals(this.creator, warp.creator) && Objects.equals(this.creationDate, warp.creationDate);
    }
    
    @Override
    public int hashCode() {
        int result = (this.id != null) ? this.id.hashCode() : 0;
        result = 31 * result + ((this.world != null) ? this.world.hashCode() : 0);
        result = 31 * result + ((this.transform != null) ? this.transform.hashCode() : 0);
        result = 31 * result + ((this.creator != null) ? this.creator.hashCode() : 0);
        result = 31 * result + ((this.creationDate != null) ? this.creationDate.hashCode() : 0);
        return result;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "Warp{id='" + this.id + "', transform=" + String.valueOf(this.transform) + ", creator='" + this.creator + "', creationDate=" + String.valueOf(this.creationDate);
    }
    
    @Nullable
    public Teleport toTeleport() {
        final World worldInstance = Universe.get().getWorld(this.world);
        if (worldInstance == null) {
            return null;
        }
        return Teleport.createForPlayer(worldInstance, this.transform);
    }
    
    static {
        CODEC = new BsonFunctionCodec<Warp>((Codec<Warp>)BuilderCodec.builder(Warp.class, Warp::new).addField(new KeyedCodec<String>("Id", Codec.STRING), (warp, s) -> warp.id = s, warp -> warp.id).addField(new KeyedCodec("World", Codec.STRING), (warp, s) -> warp.world = s, warp -> warp.world).addField(new KeyedCodec("Creator", Codec.STRING), (warp, s) -> warp.creator = s, warp -> warp.creator).append(new KeyedCodec("Date", Codec.LONG), (warp, s) -> warp.creationDate = Instant.ofEpochMilli(s), warp -> null).addValidator(Validators.deprecated()).add().append(new KeyedCodec("CreationDate", Codec.INSTANT), (o, i) -> o.creationDate = i, o -> o.creationDate).add().build(), (warp, bsonValue) -> {
            warp.transform = Transform.CODEC.decode(bsonValue);
            return warp;
        }, (bsonValue, warp) -> {
            bsonValue.asDocument().putAll(Transform.CODEC.encode(warp.transform).asDocument());
            return bsonValue;
        });
        ARRAY_CODEC = new ArrayCodec<Warp>(Warp.CODEC, Warp[]::new);
    }
}
