package com.fdkanfang.common.enums;

import io.swagger.models.auth.In;
import org.apache.commons.lang3.StringUtils;

/**
 * @author abnerhou
 * @date 2020/7/23 15:29
 * @desciption
 */
public enum ImageResolutionRate {
      TWO_K(2048,"2K分辨率" , 1),
      FOUR_K(4096,"4K分辨率" , 2),
    ;

    private Integer rate;
    private  String desc;
    private Integer order;

    ImageResolutionRate(Integer rate, String desc, Integer order) {
        this.rate = rate;
        this.desc = desc;
        this.order = order;
    }
    public static ImageResolutionRate getResolutionRateByRate(Integer rate){
        if(null == rate){
            return  null;
        }
        if(rate.compareTo(4096) < 0){
            return TWO_K;
        }else{
            return FOUR_K;
        }
    }

    public static ImageResolutionRate getResolutionByName(String name){
        if(StringUtils.isBlank(name)){
            return null;
        }
        for (ImageResolutionRate resolutionRate : values()){
            if(StringUtils.equals(name , resolutionRate.name())){
                return resolutionRate;
            }
        }
        return null;
    }

    public static Integer getSortByRate(Integer rate){
        if(null == rate){
            return  -1;
        }
        if(rate.compareTo(2048*1024) <= 0){
            return TWO_K.getOrder();
        }else{
            return FOUR_K.getOrder();
        }
    }

    public Integer getRate() {
        return rate;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getOrder() {
        return order;
    }
}
