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 {
      //最长的边不超过了8K=8192
      ONE_K(0 ,8192,"1K分辨率" , 1),
      //最长的边像素点不超过16K=16384，但是超过了4K=8192
      TWO_K(8192 ,16384,"2K分辨率" , 2),
      //最长的边像素点超过16K=16384
      FOUR_K(16384 , 999999999,"4K分辨率" , 3),
    ;

    private Integer rateStart;
    private Integer rateEnd;
    private  String desc;
    private Integer order;

    ImageResolutionRate(Integer rateStart, Integer rateEnd, String desc, Integer order) {
        this.rateStart = rateStart;
        this.rateEnd = rateEnd;
        this.desc = desc;
        this.order = order;
    }

    public static ImageResolutionRate getResolutionRateByRate(Integer rate){
        if(null == rate){
            return  null;
        }
        if(rate.compareTo(ONE_K.getRateStart()) >= 0 && rate.compareTo(ONE_K.getRateEnd()) < 0){
            return ONE_K;
        }else if(rate.compareTo(TWO_K.getRateStart()) >= 0 && rate.compareTo(TWO_K.getRateEnd()) < 0){
            return TWO_K;
        }else if(rate.compareTo(FOUR_K.getRateStart()) >= 0 && rate.compareTo(FOUR_K.getRateEnd()) < 0){
            return FOUR_K;
        }
        return null;
    }

    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 Integer getRateStart() {
        return rateStart;
    }
    public Integer getRateEnd() {
        return rateEnd;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getOrder() {
        return order;
    }

}
