package com.seer.teach.mp.admin.controller.req;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.seer.teach.common.request.PageRequest;
import com.seer.teach.mp.entity.MpParentAgentActivityRelationEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 家长参与代理商活动查询请求类
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(description = "家长参与代理商活动查询请求")
public class ParentAgentActivityQueryReq extends PageRequest {

    @Schema(description = "活动ID")
    private Integer activityId;

    @Schema(description = "代理商ID")
    private Integer agentId;

    @Schema(description = "家长ID")
    private Integer parentId;

    @Schema(description = "活动名称")
    private String activityName;

    @Schema(description = "代理商名称")
    private String agentName;

    @Schema(description = "参与状态：0-取消参与，1-正常参与")
    private Integer status;

    /**
     * 转换为查询条件
     * @return 查询条件
     */
    public LambdaQueryWrapper<MpParentAgentActivityRelationEntity> toQueryWrapper() {
        LambdaQueryWrapper<MpParentAgentActivityRelationEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(activityId != null, MpParentAgentActivityRelationEntity::getActivityId, activityId)
                .eq(agentId != null, MpParentAgentActivityRelationEntity::getAgentId, agentId)
                .eq(parentId != null, MpParentAgentActivityRelationEntity::getParentId, parentId)
                .like(activityName != null && !activityName.isEmpty(), MpParentAgentActivityRelationEntity::getActivityName, activityName)
                .like(agentName != null && !agentName.isEmpty(), MpParentAgentActivityRelationEntity::getAgentName, agentName)
                .eq(status != null, MpParentAgentActivityRelationEntity::getStatus, status)
                .orderByDesc(MpParentAgentActivityRelationEntity::getSignUpTime); // 按报名时间倒序排列
        return wrapper;
    }
}