package de.steamwar.lobby.particle;

import lombok.SneakyThrows;
import org.bukkit.util.Vector;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;

public interface WingDesign {

    @SneakyThrows
    static Vector[] create(String resource) {
        List<Vector> vectors = new ArrayList<>();
        BufferedImage bufferedImage = ImageIO.read(WingDesign.class.getResourceAsStream(resource));
        for (int x = 0; x < bufferedImage.getWidth(); x++) {
            for (int y = 0; y < bufferedImage.getHeight(); y++) {
                int rgb = bufferedImage.getRGB(x, y);
                if (Color.WHITE.getRGB() != rgb) {
                    vectors.add(new Vector(x - bufferedImage.getWidth() / 2.0, bufferedImage.getHeight() - y - 1.0, 0));
                }
            }
        }
        return vectors.toArray(new Vector[0]);
    }

    class WingDesignImpl implements WingDesign {
        private final Vector[] vectors;

        public WingDesignImpl(Vector[] vectors) {
            this.vectors = vectors;
        }

        @Override
        public Vector[] getVectors() {
            return vectors;
        }
    }

    Vector[] getVectors();

    WingDesign SIMPLE = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/WingSimple4.png"));
    WingDesign COMPLEX = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/WingSimple2.png"));
    WingDesign SWORD = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/WingSword.png"));
    WingDesign SW = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/WingSW.png"));
    WingDesign WGS = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/WingWGS.png"));
    WingDesign SWORD_CROSSED = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/WingSwordCrossed.png"));
    WingDesign MWGL = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/MWGL.png"));

    WingDesign ECLIPSE = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/ECLIPSE-Logo.png"));
    WingDesign PL = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/PL-Logo.png"));

    WingDesign PlompaEasterWings = new WingDesignImpl(create("/de/steamwar/lobby/particle/decorator/ECAL-Logo.png"));
}
