package com.sqx.modules.member.query;

import com.sqx.common.query.PageQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@ApiModel(description = "会员推广记录查询参数")
public class VipPromoRecordQuery extends PageQuery {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "推广码id")
    private Long promoCodeId;

    @ApiModelProperty(value = "用户手机号")
    private String userPhone;

    // @ApiModelProperty(value = "支付类型 1微信支付、2余额支付、3暖心照顾")
    // private String payType;

    @ApiModelProperty(value = "是否暖心照顾 1是、0否")
    private String specialFlag;
    
    @ApiModelProperty(value = "查询开始时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    @ApiModelProperty(value = "查询结束时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;

    /**
     * 拼接查询条件字符串
     * @return 拼接后的查询条件字符串
     */
    public String buildQueryConditionString() {
        StringBuilder sb = new StringBuilder();

        // 推广码id
        if (getPromoCodeId() != null) {
            sb.append("推广码id:").append(getPromoCodeId()).append(", ");
        }

        // 用户手机号
        if (getUserPhone() != null && !getUserPhone().trim().isEmpty()) {
            sb.append("用户手机号:").append(getUserPhone()).append(", ");
        }

        // 是否暖心照顾
        if (getSpecialFlag() != null && !getSpecialFlag().trim().isEmpty()) {
            String specialFlagText = "";
            switch (getSpecialFlag()) {
                case "1":
                    specialFlagText = "是";
                    break;
                case "0":
                    specialFlagText = "否";
                    break;
                default:
                    specialFlagText = getSpecialFlag();
            }
            sb.append("是否暖心照顾:").append(specialFlagText).append(", ");
        }

        // 支付类型
        // if (getPayType() != null && !getPayType().trim().isEmpty()) {
        //     String payTypeText = "";
        //     switch (getPayType()) {
        //         case "1":
        //             payTypeText = "微信支付";
        //             break;
        //         case "2":
        //             payTypeText = "余额支付";
        //             break;
        //         case "3":
        //             payTypeText = "暖心照顾";
        //             break;
        //         default:
        //             payTypeText = getPayType();
        //     }
        //     sb.append("支付类型:").append(payTypeText).append(", ");
        // }

        // 开始时间
        if (getStartTime() != null) {
            sb.append("开始时间:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(getStartTime())).append(", ");
        }

        // 结束时间
        if (getEndTime() != null) {
            sb.append("结束时间:").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(getEndTime())).append(", ");
        }

        // 分页信息
        sb.append("页码:").append(getPage()).append(", ");
        sb.append("每页条数:").append(getLimit());

        return sb.toString();
    }
}
