package com.tzy.common.dto.group;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author by po'yi
 * @Classname GroupQuery
 * @Description 组队查询参数
 * @Date 2023/2/17 15:27
 */
@Data
@Accessors(chain = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GroupQuery implements Serializable {
	private List<Long> infoIds;
	private List<Long> excludeInfoIds;
	/**搜索*/
	private String keyword;
	/**用分词搜索*/
	private String searchName;
	/**搜索*/
	private String status;
	/**运动*/
	private String sport;
	/**私域*/
	private String showApplet;
	/**活动类型*/
	private String hotType;
	private String merchantName;
	private String code;
	private String sets;
	private String type;
	private String infoType;
	private String specs;
	/**所有状态标志*/
	private String allStatus;
	private String soldTimeStart;
	private String soldTimeEnd;
	/**升序降序desc*/
	private String sort="DESC";
	/**排序字段*/
	private String sidx="startTime";
	/**状态集合*/
	private List<Integer> statusList;
	/**运动集合*/
	private List<String> sportList;
	private List<String> setList;
	private String setVersion;
	/**互相拉黑商家id*/
	private List<Long> disLikeMerchantIds;
	/**仅查近1个月*/
	private boolean onlyMaxTime;
	//每页数据条数
	private Integer rows =10;
	//页码数
	private Integer pageNo=1;

	private Integer offset;

	private Integer userId;

	private Integer userLevel;

	private Integer paniniBaseId;

	private String ownerSearchName;

	private boolean ownerFlag;
	/**智子云推荐*/
	private boolean recommendFlag;
	/**推荐组队id*/
	private List<Long> sortIds;

	private String merchantIds;
	private List<Integer> merchantIdList;
	private String hotMerchantIds;
	private List<Integer> hotMerchantIdList;
	private boolean hasAct;
	private String checkListIds;
	private List<Integer> checkListIdList;
	/**活动标签*/
	private String actType;

	private String paniniBaseIds;
	/**搜索类型,首页:home,市场页:market,搜索:search*/
	private String searchType;
	/**即将售罄*/
	private boolean almostFinished = false;
	/**即将售罄查询每个商家个数*/
	private int almostFinishedNum = 2;
	/**球队活动页查询*/
	private boolean teamActQuery = false;
	/**额外补充拼团信息,仅推荐时用*/
	private boolean extraAddInfo = false;
	private boolean searchSold = false;
	private List<Integer> paniniBaseIdList;
	/**私域显示活动类型*/
	private List<String> privateShowTypes;
	/**推荐页中需排除的拼团id集合*/
	private List<Integer> excludeIds;
	/** 厂商 **/
	private String manufacturer;
	/**是否可用优惠劵,默认0:可以,1:不允许*/
	private Integer useCoupon;
	private String useSport; // 去使用优惠券指定运动类型
	private String useManufacturer; // 去使用优惠券指定厂商
	public List<Integer> getPaniniBaseIdList() {
		if(StringUtils.isNotEmpty(paniniBaseIds)){
			return Arrays.stream(paniniBaseIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
		}
		return paniniBaseIdList;
	}

	public List<Integer> getCheckListIdList() {
		if(StringUtils.isNotEmpty(checkListIds)){
			return Arrays.stream(checkListIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
		}
		return checkListIdList;
	}

	public List<Integer> getMerchantIdList() {
		if(StringUtils.isNotEmpty(merchantIds)){
			return Arrays.stream(merchantIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
		}
		return merchantIdList;
	}

	public List<Integer> gethotMerchantIdList() {
		if(StringUtils.isNotEmpty(hotMerchantIds)){
			return Arrays.stream(hotMerchantIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
		}
		return hotMerchantIdList;
	}

	public Integer getOffset() {
		if (this.pageNo == null || this.rows == null) {
			return null;
		}
		return ((pageNo) - 1) * rows;
	}

	public List<Integer> getStatusList() {
		if(this.statusList!=null){
			return statusList;
		}

		if(StringUtils.isEmpty(this.status)){
			return statusList;
		}
		return Arrays.stream(this.status.split(",")).map(Integer::valueOf).collect(Collectors.toList());
	}

	public List<String> getSetList() {
		if(StringUtils.isEmpty(this.sets)){
			return setList;
		}
		return Arrays.stream(this.status.split(",")).map(String::toLowerCase).collect(Collectors.toList());
	}
}
