package com.cool.store.enums.point;

import java.util.Objects;

/**
 * @author zhangchenbiao
 * @FileName: FlowRateCalculateEnum
 * @Description:人流测算(18点-20点)
 * @date 2024-03-26 16:08
 */
public enum FlowRateCalculateEnum {

    //1.>400人/时以上, 2.300～400人/时, 3.200～300人/时, 4.100～200人/时
    FLOW_RATE_CALCULATE_1(1, ">400人/时以上", 8),
    FLOW_RATE_CALCULATE_2(2, "300～400人/时", 6),
    FLOW_RATE_CALCULATE_3(3, "200～300人/时", 5),
    FLOW_RATE_CALCULATE_4(4, "100～200人/时", 3),
    ;

    private Integer code;

    private String desc;

    private Integer score;

    FlowRateCalculateEnum(Integer code, String desc, Integer score) {
        this.code = code;
        this.desc = desc;
        this.score = score;
    }

    public Integer getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getScore() {
        return score;
    }

    public static FlowRateCalculateEnum getByCode(Integer code) {
        if(Objects.isNull(code)){
            return null;
        }
        for (FlowRateCalculateEnum value : FlowRateCalculateEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 获取人流测算
     * @param nineFlowRate
     * @param tenFlowRate
     * @param eighteenFlowRate
     * @param nineteenFlowRate
     * @return
     */
    public static FlowRateCalculateEnum getByFlowRate(Integer nineFlowRate, Integer tenFlowRate, Integer eighteenFlowRate, Integer nineteenFlowRate){
        Integer flowRate = 0, count = 0;
        if(Objects.nonNull(nineFlowRate)){
            flowRate += nineFlowRate;
            count++;
        }
        if(Objects.nonNull(tenFlowRate)){
            flowRate += tenFlowRate;
            count++;
        }
        if(Objects.nonNull(eighteenFlowRate)){
            flowRate += eighteenFlowRate;
            count++;
        }
        if(Objects.nonNull(nineteenFlowRate)){
            flowRate += nineteenFlowRate;
            count++;
        }
        if(count == 0){
            count = 1;
        }
        flowRate = flowRate / count;
        if(flowRate > 400){
            return FLOW_RATE_CALCULATE_1;
        }
        if(flowRate > 300 && flowRate <= 400){
            return FLOW_RATE_CALCULATE_2;
        }
        if(flowRate > 200 && flowRate <= 300){
            return FLOW_RATE_CALCULATE_3;
        }
        return FLOW_RATE_CALCULATE_4;
    }

}
