package leigh.minecraft.leighco;

import leigh.mecha.log.MechaLogger;
import leigh.mecha.log.MechaLoggerFactory;

public class Lot {
    private static final MechaLogger logger = MechaLoggerFactory.getLogger(Lot.class);

    private int x1, x2, z1, z2;

    public Lot(int x1, int x2, int z1, int z2) {
        this.x1 = x1;
        this.x2 = x2;
        this.z1 = z1;
        this.z2 = z2;
    }

    public Lot(Location loc, int size) {
        // Just to get to integer
        int px = (int) Math.abs(loc.getX());
        int pz = (int) Math.abs(loc.getZ());

        this.x1 = (px / size) * size;
        this.z1 = (pz / size) * size;

        this.x2 = x1 + size - 1;
        this.z2 = z1 + size - 1;

        if (loc.getX() < 0) {
            this.x1 = -this.x1;
            this.x2 = -this.x2;
            this.x1--;
            this.x2--;
        }
        if (loc.getZ() < 0) {
            this.z1 = -this.z1;
            this.z2 = -this.z2;
            this.z1--;
            this.z2--;
        }
    }

    public int getX1() {
        return x1;
    }

    public int getX2() {
        return x2;
    }

    public int getZ1() {
        return z1;
    }

    public int getZ2() {
        return z2;
    }

    @Override
    public String toString() {
        return "Lot{" +
                "x1=" + x1 +
                ", z1=" + z1 +
                ", x2=" + x2 +
                ", z2=" + z2 +
                '}';
    }
}
