package eu.mhsl.minecraft.pixelpics.render.render;

import com.google.common.base.Preconditions;

import java.util.*;

public final class Resolution {

    private final int width;
    private final int height;

    public Resolution(Pixels pixels, AspectRatio aspectRatio) {
        Preconditions.checkNotNull(pixels);
        Preconditions.checkNotNull(aspectRatio);

        this.height = pixels.height;
        this.width = (int) Math.round(pixels.height * aspectRatio.ratio);
    }

    public Resolution(int width, int height) {
        Preconditions.checkArgument(width > 0);
        Preconditions.checkArgument(height > 0);

        this.width = width;
        this.height = height;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public enum Pixels {
        _128P(128, "128p"),
        _256P(256, "256p");

        private final int height;
        private final List<String> aliases;

        Pixels(int height, String... aliases) {
            this.height = height;
            this.aliases = Collections.unmodifiableList(Arrays.asList(aliases));
        }
    }

    public enum AspectRatio {
        _1_1(1, "1:1"),
        _2_1(2, "2:1"),
        _3_2(3 / 2.0, "3:2");

        private final double ratio;
        private final List<String> aliases;

        AspectRatio(double ratio, String... aliases) {
            this.ratio = ratio;
            this.aliases = Collections.unmodifiableList(Arrays.asList(aliases));
        }
    }
}