package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LifeBlacklist;
import shop.alien.entity.store.vo.LifeBlacklistVo;

import java.util.List;

/**
 * <p>
 * 黑名单
 Mapper 接口
 * </p>
 *
 * @author ssk
 * @since 2025-04-30
 */
public interface LifeBlacklistMapper extends BaseMapper<LifeBlacklist> {

    List<LifeBlacklist> selectListByUserId(LambdaUpdateWrapper<LifeBlacklist> wrapper);

    /**
     * 获取拉黑列表
     *
     * @param userId 用户id
     * @return 拉黑用户id 集合
     */
    List<Integer> getBlackList(Integer userId);

    @Select("select if (black.blocked_type = '2', concat('user_', user.user_phone), concat('store_', suser.phone)) phoneId " +
            "from life_blacklist black " +
            "left join life_user user on user.id = black.blocked_id and black.blocked_type = '2' and user.delete_flag = 0 " +
            "left join store_user suser on suser.id = black.blocked_id and black.blocked_type = '1' and suser.delete_flag = 0 " +
            "where black.blocker_type = #{userType} and black.blocker_id = #{userId} and black.delete_flag = 0 ")
    List<LifeBlacklistVo> getPhoneIdByUserId(@Param("userType") String userType, @Param("userId") String userId);
}
