package com.zhentao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhentao.entity.ActivityRegistration;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 活动报名记录Mapper
 */
@Mapper
public interface ActivityRegistrationMapper extends BaseMapper<ActivityRegistration> {
    
    /**
     * 查询用户的活动报名记录（关联活动信息）
     */
    @Select("SELECT " +
            "ar.id, ar.activity_id, ar.user_id, ar.registration_time, ar.status, " +
            "ar.created_time, ar.updated_time, " +
            "a.name AS activityName, a.cover_image AS coverImage, " +
            "a.start_time AS startTime, a.end_time AS endTime, " +
            "a.location, a.price, a.max_participants AS maxParticipants, " +
            "a.actual_participants AS actualParticipants, a.status AS activityStatus " +
            "FROM activity_registration ar " +
            "LEFT JOIN activity a ON ar.activity_id = a.id " +
            "WHERE ar.user_id = #{userId} AND ar.status = #{status} " +
            "ORDER BY ar.created_time DESC")
    List<ActivityRegistration> selectUserRegistrations(@Param("userId") Integer userId, @Param("status") Integer status);
    
    /**
     * 查询用户的所有活动报名记录
     */
    @Select("SELECT " +
            "ar.id, ar.activity_id, ar.user_id, ar.registration_time, ar.status, " +
            "ar.created_time, ar.updated_time, " +
            "a.name AS activityName, a.cover_image AS coverImage, " +
            "a.start_time AS startTime, a.end_time AS endTime, " +
            "a.location, a.price, a.max_participants AS maxParticipants, " +
            "a.actual_participants AS actualParticipants, a.status AS activityStatus " +
            "FROM activity_registration ar " +
            "LEFT JOIN activity a ON ar.activity_id = a.id " +
            "WHERE ar.user_id = #{userId} " +
            "ORDER BY ar.created_time DESC")
    List<ActivityRegistration> selectAllUserRegistrations(@Param("userId") Integer userId);
}


