package com.ningdatech.carapi.analysis.entity.req;

import cn.hutool.core.util.StrUtil;
import com.ningdatech.basic.model.PagePo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

/**
 * <p>
 * SecurityRiskEvaluationListReq
 * </p>
 *
 * @author WendyYang
 * @since 09:27 2022/10/14
 */
@ApiModel("安全责任体系分析评估列表参数类")
@Data
@EqualsAndHashCode(callSuper = true)
public class SecurityRiskEvalListReq extends PagePo {

    private Long regionId;

    private Integer year;

    @ApiModelProperty("总分值：格式为-XX，XX-XX，XX-")
    private String scoreRange;

    private String companyName;

    private transient Pair<Integer, Integer> scoreRanges;

    public void setScoreRange(String scoreRange) {
        this.scoreRange = scoreRange;
        this.setScoreRanges();
    }

    private void setScoreRanges() {
        if (StringUtils.isNotBlank(this.scoreRange)) {
            String[] scoreArray = StrUtil.strip(scoreRange, "-").split("-");
            int indexOf = scoreRange.indexOf("-");
            if (indexOf == scoreRange.length() - 1) {
                scoreRanges = Pair.of(Integer.valueOf(scoreArray[0]), null);
            } else if (indexOf == 0) {
                scoreRanges = Pair.of(null, Integer.valueOf(scoreArray[0]));
            } else {
                scoreRanges = Pair.of(Integer.valueOf(scoreArray[0]), Integer.valueOf(scoreArray[1]));
            }
        }
    }

}
