package com.tykj.model.service;



import com.tykj.base.consumer.FourComsumer;
import com.tykj.model.entity.ColumnInfo;
import com.tykj.model.entity.TableInfo;
import com.tykj.model.entity.vo.*;


import org.hibernate.internal.SessionImpl;
import org.hibernate.type.Type;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;

/**
 * @ClassName ModelService
 * @Description TODO
 * @Author WWW
 * @Date 2021/2/26 13:36
 * @Version 1.0
 */
public interface ModelService {

    /**
     * 分页查询
     *
     * @param searchTableInfoVo
     * @return
     */
    Page<TableInfo> pageAllEntities(SearchTableInfoVo searchTableInfoVo);


    /**
     * 方法重载不分页查询
     *
     * @return
     */
    List<TableInfo> listAllEntities(SearchTableInfoVo searchTableInfoVo);


    /**
     * 根据表名查询所有字段信息
     *
     * @param searchColumnInfoVo
     * @return
     */
    List<ColumnInfo> showModelFields(SearchColumnInfoVo searchColumnInfoVo);


    /**
     * 新建模型
     *
     * @param tableVO
     * @return
     */

    TableInfo newTable(TableVO tableVO);

    /**
     *
     *根据表名插入数据
     * @param map
     * @return
     */
    int operationValueByEntityName(Map<String, Object> map,
                                   SessionImpl session,
                                   BiConsumer<String, Object> biConsumer,
                                   FourComsumer<TableInfo, Object, Type, String> valitor);

    int operationValueByEntityNameList(List<Map<String, Object>> mapList,
                                       SessionImpl session,
                                       BiConsumer<String, Object> biConsumer,
                                       FourComsumer<TableInfo, Object, Type, String> valitor);
    /**
     * 根据表名查询所有
     *
     * @param name
     * @return
     * @throws SQLException
     */
    List<Map<String, Object>> findAllByName(String name) throws SQLException;

    List<Map<String, Object>> findAllByName(String name, List<OrderCondition> orderConditions) ;
    /**
     * 复杂查询
     *
     * @param tableName
     * @param queryConditions
     * @return
     */
    List<Map<String, Object>> complexQuery(String tableName,
                                           List<String> columnNames,
                                           List<QueryCondition> queryConditions,
                                           String groupName);

    /**
     * 复杂查询（带分类）
     *
     * @param tableName
     * @param queryConditions
     * @return
     */
    CustomPage complexQueryWithGroup(String tableName,
                                     GroupCondition groupCondition,
                                     List<String> columnNames,
                                     List<QueryCondition> queryConditions,
                                     String groupByColumn,
                                     Integer page,
                                     Integer size);


    /**
     * 修改表
     *
     * @param updateTableInfoVO
     * @return
     */
    String updateTable(UpdateTableInfoVO updateTableInfoVO);


    /**
     * 删除表
     *
     * @param delTableVO
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    int delTable(DelTableVO delTableVO);


    /**
     * 根据id批量查询所有tableInfo和ColumnInfo
     *
     * @param ids
     * @return
     */
    TableAndColumnInfoVO getTableInfoAndColumnInfoByBatch(Integer[] ids);

    /**
     * 执行自定义SQL
     * @param sql
     * @return
     * @throws SQLException
     */
    List<Map<String, Object>> executeQuery(String sql) throws SQLException;



    void validationAllRuleAndQuote(TableInfo tableInfo, Object value, Type propertyType, String propertyNames);

    void deleteAllBytableName(String tableName);

}
