package nl.sbdeveloper.themeparkplus.api.objects;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import nl.sbdeveloper.themeparkplus.api.enums.WalkingDirection;
import org.bukkit.Bukkit;
import org.bukkit.Location;

import java.util.Objects;

@Getter @Setter @NoArgsConstructor @AllArgsConstructor
public class Gate {
    private String world;
    private int x;
    private int y;
    private int z;

    /* If max count */
    private boolean hasMaxCount = false;
    private int passedCount = 0;
    private int maxCount;

    /* If directional */
    private boolean isDirectional = false;
    private WalkingDirection direction;

    /**
     * Constructor for a directional gate.
     *
     * @param loc The gate location
     * @param direction The walking direction
     */
    public Gate(Location loc, WalkingDirection direction) {
        this.world = Objects.requireNonNull(loc.getWorld(), "World is null!").getName();
        this.x = loc.getBlockX();
        this.y = loc.getBlockY();
        this.z = loc.getBlockZ();
        this.isDirectional = true;
        this.direction = direction;
    }

    /**
     * Constructor for a max count gate.
     *
     * @param loc The gate location
     * @param maxCount The max player count
     */
    public Gate(Location loc, int maxCount) {
        this.world = Objects.requireNonNull(loc.getWorld(), "World is null!").getName();
        this.x = loc.getBlockX();
        this.y = loc.getBlockY();
        this.z = loc.getBlockZ();
        this.hasMaxCount = true;
        this.maxCount = maxCount;
    }

    /**
     * Constructor for a directional max count gate.
     *
     * @param loc The gate location
     * @param maxCount The max player count
     * @param direction The walking direction
     */
    public Gate(Location loc, int maxCount, WalkingDirection direction) {
        this.world = Objects.requireNonNull(loc.getWorld(), "World is null!").getName();
        this.x = loc.getBlockX();
        this.y = loc.getBlockY();
        this.z = loc.getBlockZ();
        this.hasMaxCount = true;
        this.isDirectional = true;
        this.maxCount = maxCount;
        this.direction = direction;
    }

    public Location getLoc() {
        return new Location(Bukkit.getWorld(this.world), this.x, this.y, this.z);
    }
}
