package com.ruoyi.benyun.entity.vo;

import com.ruoyi.benyun.valida.TopologicalWdGroup;
import com.ruoyi.benyun.valida.TopologicalWdListGroup;
import com.ruoyi.benyun.constant.ChannelMapContant;
import com.ruoyi.benyun.utils.HashUtil;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Data
public class TopologicalWdAceeptVo {

    //中心网点Id
    @NotBlank(groups = {TopologicalWdGroup.class, TopologicalWdListGroup.class},message = "请选择中心点")
    String centerWdId;

    //半径范围
    @NotNull(groups = {TopologicalWdGroup.class,TopologicalWdListGroup.class},message = "半径范围未正确选择")
    int radius;

    //地区Code
    String addrCode;

    //限制条数
    int size = 10;

    //网点分类
    String[] channel;


    public String getHash(){
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(centerWdId);
        stringBuilder.append(radius);
        stringBuilder.append(size);

        for (String s : getChannel()) {
            stringBuilder.append(s);
        }


        String s = stringBuilder.toString();
        String md5 = HashUtil.hash(s, "MD5");
        return md5;
    }

    public String[] getChannel() {
        if(this.channel == null || this.channel.length == 0){
            return channel = ChannelMapContant.FULL_CHANNEL;
        }
        return channel;
    }

}
