package com.nanri.aiimage.modules.dedupe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nanri.aiimage.modules.dedupe.model.entity.DedupeTotalDataEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;
import java.util.StringJoiner;

@Mapper
public interface DedupeTotalDataMapper extends BaseMapper<DedupeTotalDataEntity> {

    @Select("SELECT data_value FROM biz_dedupe_total_data")
    List<String> selectAllDataValues();

    @SelectProvider(type = SqlProvider.class, method = "selectExistingDataValues")
    List<String> selectExistingDataValues(@Param("values") List<String> values);

    class SqlProvider {
        public String selectExistingDataValues(@Param("values") List<String> values) {
            StringJoiner placeholders = new StringJoiner(", ");
            for (int i = 0; i < values.size(); i++) {
                placeholders.add("#{values[" + i + "]}");
            }
            return "SELECT data_value FROM biz_dedupe_total_data WHERE data_value IN (" + placeholders + ")";
        }
    }
}
