package com.backendsys.modules.crt.enums;

public enum AspectRatioEnums {

    RATIO_16_9("16:9", 1280, 720),
    RATIO_9_16("9:16", 720, 1280),
    RATIO_1_1("1:1", 1024, 1024)
    ;

    private final String key;
    private final Integer width;
    private final Integer height;

    AspectRatioEnums(String key, Integer width, Integer height) {
        this.key = key;
        this.width = width;
        this.height = height;
    }

    public Integer getWidth() {
        return this.width;
    }
    public Integer getHeight() {
        return this.height;
    }
    public String getKey() {
        return this.key;
    }

    /* 根据 key 返回枚举，找不到返回 null */
    public static AspectRatioEnums of(String key) {
        for (AspectRatioEnums e : values()) {
            if (e.key.equals(key)) {
                return e;
            }
        }
        return null;
    }

    /*
         int[] size = AspectRatioEnums.getAspectRatio("16:9");
         // [1280, 720]
     */
    public static int[] getAspectRatio(String key) {
        AspectRatioEnums e = of(key);
        return e == null ? null : new int[]{e.width, e.height};
    }
    /*
        String sizeStr = AspectRatioEnums.getAspectRatioString("16:9");
        // "1280*720"
    */
    public static String getAspectRatioString(String key) {
        AspectRatioEnums e = of(key);
        return e == null ? null : e.width + "*" + e.height;
    }

}
