package shop.alien.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LawyerImg;
import shop.alien.entity.store.vo.LawyerImgTypeVo;

import java.util.List;

/**
 * 律师图片 Mapper 接口
 *
 * @author system
 * @since 2025-01-XX
 */
@Mapper
public interface LawyerImgMapper extends BaseMapper<LawyerImg> {

    @Select("select IFNULL(img_type, 0) img_type, count(1) count, img_url imgUrl from lawyer_img where lawyer_id = #{lawyerId} and img_type = 0 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 1) img_type, count(1) count, img_url imgUrl from lawyer_img where lawyer_id = #{lawyerId} and img_type = 1 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 2) img_type, count(1) count, img_url imgUrl from lawyer_img where lawyer_id = #{lawyerId} and img_type = 2 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 5) img_type, count(1) count, img_url imgUrl from lawyer_img where lawyer_id = #{lawyerId} and img_type = 5 and delete_flag= 0 " +
            "union all " +
            "select IFNULL(img_type, 6) img_type, count(1) count, img_url imgUrl from lawyer_img where lawyer_id = #{lawyerId} and img_type = 6 and delete_flag= 0")
    List<LawyerImgTypeVo> getLawyerImgTypeCount(@Param("lawyerId") Integer lawyerId);

    /**
     * 根据业务ID获取图片
     *
     * @param queryWrapper 查询条件
     * @return 图片列表
     */
    @Select("SELECT * " +
            "FROM lawyer_img ${ew.customSqlSegment}")
    List<LawyerImg> getImgsByBusinessIds(@Param(Constants.WRAPPER) QueryWrapper<LawyerImg> queryWrapper);



    /**
     * 根据ID获取律师图片
     *
     * @param id 图片ID
     * @return 律师图片信息
     */
    @Select("SELECT " +
            "id, " +
            "lawyer_id," +
            " img_type, " +
            "img_description, " +
            "img_sort, " +
            "img_url, " +
            "delete_flag, " +
            "created_time, " +
            "created_user_id, " +
            "updated_time, " +
            "updated_user_id, " +
            "business_id "+
            "FROM " +
            "lawyer_img " +
            "WHERE " +
            "id = #{id} " +
            "AND " +
            "delete_flag = 0")
    LawyerImg getLawyerImgById(@Param("id") Integer id);
}

