package com.sonic.daosupport.mysql;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sonic.daosupport.wrapper.CriteriaWrapper;
import com.sonic.daosupport.wrapper.SimpleWrapperConverter;

/**
 * @author code
 */
public class QueryWrapperHelper {

    public static <T> QueryWrapper<T> fromMap(Object bean, Class<T> clazz) {
        SimpleWrapperConverter converter = MybatisPlusConverterUtils.getWrapperConverter(clazz);
        return converter.toWrapper(CriteriaWrapper.fromBean(bean));
    }
// TODO: 暂时不支持返回 LambdaQueryWrapper
//    public static <T> LambdaQueryWrapper<T> getLambdaQueryWrapperFromBean(Object bean, Class<T> clazz) {
//        SimpleWrapperConverter converter = MybatisPlusConverterUtils.getWrapperConverter(clazz);
//        return converter.toLambdaWrapper(CriteriaWrapper.fromBean(bean));
//    }

    public static <T> QueryWrapper<T> fromMap(Map<String, Object> map, Class<T> clazz) {
        SimpleWrapperConverter converter = MybatisPlusConverterUtils.getWrapperConverter(clazz);
        return converter.toWrapper(CriteriaWrapper.builder().queryField(map).build());
    }
// TODO: 暂时不支持返回 LambdaQueryWrapper
//    public static <T> LambdaQueryWrapper<T> getLambdaQueryWrapperFromMap(Map<String, Object> map, Class<T> clazz) {
//        SimpleWrapperConverter converter = MybatisPlusConverterUtils.getWrapperConverter(clazz);
//        return converter.toLambdaWrapper(CriteriaWrapper.builder().queryField(map).build());
//    }

}
