package com.tzy.common.dto.group;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.tzy.common.utils.StringUtils;
import lombok.Data;
import lombok.experimental.Accessors;

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

/**
 * @author by po'yi
 * @Classname NonEmptyOrderDTO
 * @Description TODO
 * @Date 2023/8/18 13:37
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
@Accessors(chain = true)
public class NonEmptyQuery implements Serializable {

    private Integer merchantId;
    private boolean shippedFlag;
    //用户code,模糊搜索
    private String code;
    private Integer pageNo = 1;
    private Integer pageSize = 10;
    private Integer offset;
    //待用户申请
    private boolean waitApply;
    private boolean hasAddr=true;
    //用户拥有数量上限
    private Integer maxNum;
    //用户拥有数量下限
    private Integer minNum;
    //卡片类型
    private Integer cardId;
    private String userIds;

    private List<Integer> userIdList;

    public Integer getOffset() {
        if (offset != null) {
            return offset;
        }
        if (this.pageNo == null || this.pageSize == null) {
            return 0;
        }
        return ((pageNo) - 1) * pageSize;
    }

    public List<Integer> getUserIdList() {
        if (StringUtils.isNotEmpty(userIds)) {
            return Arrays.stream(userIds.split(",")).map(Integer::parseInt).collect(Collectors.toList());
        }
        return userIdList;
    }
}
