package com.ruoyi.demo.entity.vo;


import com.ruoyi.demo.constant.ChannelMapContant;
import com.ruoyi.demo.utils.HashUtil;
import com.ruoyi.demo.valida.ChannelAreaGroup;
import com.ruoyi.demo.valida.ChannelListGroup;
import com.ruoyi.demo.valida.ChannelPointGroup;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.io.Serializable;

@Data
public class ChannelMapAceeptVo implements Serializable {

    /*
    * 搜索字段
    * */
    String searchText;  //网点关键字
    String brandName; //品牌名称

    /*
    * 分类字段
    * */
    String[] channel;  //渠道分类（0：基础设施网点、1：门店网点、2：小区网点、3：楼宇网点、4：交通设施网点、5：公司网点）

    @NotBlank(groups = { ChannelAreaGroup.class, ChannelListGroup.class},message = "rankType不能为空")
    String rankType; //搜索等级（province：搜索省、city：搜素市、zone：搜素区）

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

    String[] cityTier; //["一线"，"新一线"、"二线"、"三线"、"四线"、"五线"]

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

    String isBrand = ""; //有无关联品牌

    String isTelephone = ""; //有无联系方式

    String storeAge = ""; //店零
    int size = 15; //tag分析时候用

    /*
    * 分页字段（list、point接口）
    * */
    Integer pageNum = 1;
    Integer 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();

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

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

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


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

        //城市等级
        if(this.cityTier != null && this.cityTier.length > 0){
            for (String s : this.cityTier) {
                stringBuilder.append(s);
            }
        }

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

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

        return md5;
    }
}
