package com.benyun.core.entity.vo;

import com.benyun.core.constant.ChannelMapContant;
import com.benyun.core.utils.HashUtil;
import com.benyun.core.valida.ChannelAreaGroup;
import com.benyun.core.valida.ChannelListGroup;
import com.benyun.core.valida.ChannelPointGroup;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

@Data
public class ChannelMapAceeptVo {

    String[] channel;  //网点类型，渠道（0：基础设施网点、1：门店网点、2：小区网点、3：楼宇网点、4：交通设施网点、5：公司网点）
    @NotBlank(groups = { ChannelAreaGroup.class, ChannelListGroup.class},message = "rankType不能为空")
    String rankType; //搜索等级（province：搜索省、city：搜素市、zone：搜素区）

    String searchText; //搜索关键字

    /*
    * 地区编码code
    * 当 rankType = province,city 需要提交省区码编码
    * 当 rankType = zone 需要提交市区码编码
    * */
    @NotEmpty(groups = {ChannelPointGroup.class})
    String[] addrCode;

    String orderby = "collect_time"; //排序字段，(list接口)

    /*
    * 分页字段（list、point接口）
    * */
    int pageNum = 1;
    int pageSize = 10;


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

    public String[] getAddrCode() {
        if(this.addrCode == null || this.addrCode.length == 0){
            this.addrCode = ChannelMapContant.FULL_PROVINCE;
        }
        return addrCode;
    }

    public String getHash(){
        StringBuilder stringBuilder = new StringBuilder();

        //搜索渠道
        for (String s : getChannel()) {
            stringBuilder.append(s);
        }

        //搜索等级
        stringBuilder.append(this.rankType);

        //搜索文本
        stringBuilder.append(this.searchText);

        //搜索地区
        for (String s : getAddrCode()) {
            stringBuilder.append(s);
        }

        stringBuilder.append(pageNum);
        stringBuilder.append(pageSize);

        //生成Hash
        String s = stringBuilder.toString();
        String md5 = HashUtil.hash(s, "MD5");

        return md5;
    }
}
