package com.wzj.soopin.member.domain.bo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzj.soopin.member.domain.po.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.dromara.common.core.domain.BaseBO;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 会员信息 查询 对象
 *
 * @author zcc
 */
@Schema(description = "会员信息 查询 对象")
@Data
public class MemberBO extends BaseBO {


    @Schema(description = "id")
    private Long id;


    @Schema(description = "昵称 精确匹配")
    private String nickname;

    @Schema(description = "密码 精确匹配")
    private String password;

    @Schema(description = "手机号码 精确匹配")
    private String phone;

    @Schema(description = "有无备注 1：有备注  0：无备注")
    private Integer hasMark;

    @Schema(description = "用户备注 精确匹配")
    private String mark;

    @Schema(description = "帐号启用状态:0->禁用；1->启用 精确匹配")
    private Integer status;

    @Schema(description = "头像 精确匹配")
    private String avatar;

    @Schema(description = "性别：0->未知；1->男；2->女 精确匹配")
    private Integer gender;

    @Schema(description = "用户所在城市 精确匹配")
    private String city;

    @Schema(description = "用户所在省份 精确匹配")
    private String province;

    @Schema(description = "用户所在国家 精确匹配")
    private String country;

    @Schema(description = "生日 精确匹配")
    private LocalDate birthday;

    @Schema(description = "推广员id 精确匹配")
    private Long spreadUid;

    @Schema(description = "推广员关联时间 精确匹配")
    private LocalDateTime spreadTime;

    @Schema(description = "等级 精确匹配")
    private Integer level;

    @Schema(description = "用户剩余积分 精确匹配")
    private BigDecimal integral;


    public QueryWrapper<Member> toWapper() {
        QueryWrapper<Member> qw = new QueryWrapper<>();
        qw.lambda()
            .like(StringUtils.isNotEmpty(this.getNickname()), Member::getNickname, this.getNickname())
            .eq(getId() != null, Member::getId, this.getId())
            .eq(status != null, Member::getStatus, status)
            .eq(StringUtils.isNotEmpty(this.getPhone()), Member::getPhoneEncrypted, phone);
        qw.ge(getBeginTime() != null, "create_time", this.getBeginTime());
        qw.lt(getEndTime() != null, "create_time", this.getEndTime());
        if (this.getHasMark() != null) {
            switch (this.getHasMark()) {
                case 0:
                    qw.isNull("mark").or().eq("mark", "");
                    break;
                case 1:
                    qw.isNotNull("mark").ne("mark", "");
                    break;
                default:
                    break;
            }
        }
        return qw;
    }
}
