package cn.ibizlab.core.data.service;

import cn.ibizlab.core.data.domain.DOModel;
import cn.ibizlab.core.data.dto.BaseData;
import cn.ibizlab.core.data.dto.RequestData;
import cn.ibizlab.core.data.dto.ResponseData;
import cn.ibizlab.util.filter.SearchContextBase;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;

public interface IDataService
{

    default ResponseData call(String system,String entity,String method,RequestData requestData)
    {
        return call(system,"",entity,method,"",requestData);
    }
    default ResponseData call(RequestData requestData)
    {
        return call(getDOModel(requestData.getSystem(),requestData.getEntity()),requestData.getScope(),requestData.getMethod(),requestData.getDataSource(),requestData);
    }
    default boolean create(String system,String entity,BaseData et)
    {
        return create(getDOModel(system,entity),"",et);
    }
    default  void createBatch(String system,String entity,List<BaseData> list)
    {
        createBatch(getDOModel(system,entity),"",list);
    }
    default boolean update(String system,String entity,BaseData et)
    {
        return update(getDOModel(system,entity),"",et);
    }
    default void updateBatch(String system,String entity,List<BaseData> list)
    {
        updateBatch(getDOModel(system,entity),"",list);
    }
    default boolean remove(String system,String entity,Serializable key)
    {
        return remove(getDOModel(system,entity),"",key);
    }
    default void removeBatch(String system,String entity,List<Serializable> idList)
    {
        removeBatch(getDOModel(system,entity),"",idList);
    }
    default BaseData get(String system,String entity,Serializable key)
    {
        return get(getDOModel(system,entity),"",key);
    }
    default BaseData getDraft(String system,String entity,BaseData et)
    {
        return getDraft(getDOModel(system,entity),"",et);
    }
    default boolean checkKey(String system,String entity,BaseData et)
    {
        return checkKey(getDOModel(system,entity),"",et);
    }
    default boolean save(String system,String entity,BaseData et)
    {
        return save(getDOModel(system,entity),"",et);
    }
    default void saveBatch(String system,String entity,List<BaseData> list)
    {
        saveBatch(getDOModel(system,entity),"",list);
    }

    default Page<BaseData> fetch(String system,String entity, String dataSet,SearchContextBase context)
    {
        return fetch(getDOModel(system,entity),dataSet,"",context);
    }
    default List<BaseData> list(String system,String entity, String dataSet,SearchContextBase context)
    {
        return list(getDOModel(system,entity),dataSet,"",context);
    }

    default Page<BaseData> fetchDefault(String system,String entity,SearchContextBase context)
    {
        return fetchDefault(getDOModel(system,entity),"",context);
    }
    default List<BaseData> listDefault(String system,String entity,SearchContextBase context)
    {
        return listDefault(getDOModel(system,entity),"",context);
    }


    DOModel getDOModel(String system,String entity);

    ResponseData call(DOModel model,String scope,String method,String datasource, RequestData requestData);

    boolean create(DOModel model,String datasource,BaseData et);
    void createBatch(DOModel model,String datasource,List<BaseData> list);
    boolean update(DOModel model,String datasource,BaseData et);
    void updateBatch(DOModel model,String datasource,List<BaseData> list);
    boolean remove(DOModel model,String datasource, Serializable key);
    void removeBatch(DOModel model,String datasource,List<Serializable> idList);
    BaseData get(DOModel model,String datasource,Serializable key);
    BaseData getDraft(DOModel model,String datasource,BaseData et);
    boolean checkKey(DOModel model,String datasource,BaseData et);
    boolean save(DOModel model,String datasource,BaseData et);
    void saveBatch(DOModel model,String datasource,List<BaseData> list);

    Page<BaseData> fetch(DOModel model,String dataSet,String datasource,SearchContextBase context);
    List<BaseData> list(DOModel model,String dataSet,String datasource,SearchContextBase context);

    default Page<BaseData> fetchDefault(DOModel model,String datasource,SearchContextBase context){
        return fetch(model,"default",datasource,context);
    }
    default List<BaseData> listDefault(DOModel model,String datasource,SearchContextBase context){
        return list(model,"default",datasource,context);
    }

    default ResponseData call(String system,String scope,String entity,String method,String datasource,RequestData requestData)
    {
        requestData.setSystem(system).setScope(scope).setEntity(entity).setMethod(method).setDataSource(datasource);
        return call(getDOModel(system,entity),scope,method,datasource,requestData);
    }
    default boolean create(String system,String entity,String datasource,BaseData et)
    {
        return create(getDOModel(system,entity),datasource,et);
    }
    default  void createBatch(String system,String entity,String datasource,List<BaseData> list)
    {
        createBatch(getDOModel(system,entity),datasource,list);
    }
    default boolean update(String system,String entity,String datasource,BaseData et)
    {
        return update(getDOModel(system,entity),datasource,et);
    }
    default void updateBatch(String system,String entity,String datasource,List<BaseData> list)
    {
        updateBatch(getDOModel(system,entity),datasource,list);
    }
    default boolean remove(String system,String entity,String datasource,Serializable key)
    {
        return remove(getDOModel(system,entity),datasource,key);
    }
    default void removeBatch(String system,String entity,String datasource,List<Serializable> idList)
    {
        removeBatch(getDOModel(system,entity),datasource,idList);
    }
    default BaseData get(String system,String entity,String datasource,Serializable key)
    {
        return get(getDOModel(system,entity),datasource,key);
    }
    default BaseData getDraft(String system,String entity,String datasource,BaseData et)
    {
        return getDraft(getDOModel(system,entity),datasource,et);
    }
    default boolean checkKey(String system,String entity,String datasource,BaseData et)
    {
        return checkKey(getDOModel(system,entity),datasource,et);
    }
    default boolean save(String system,String entity,String datasource,BaseData et)
    {
        return save(getDOModel(system,entity),datasource,et);
    }
    default void saveBatch(String system,String entity,String datasource,List<BaseData> list)
    {
        saveBatch(getDOModel(system,entity),datasource,list);
    }
    default Page<BaseData> fetch(String system,String entity,String dataSet,String datasource,SearchContextBase context)
    {
        return fetch(getDOModel(system,entity),dataSet,datasource,context);
    }
    default List<BaseData> list(String system,String entity,String dataSet,String datasource,SearchContextBase context)
    {
        return list(getDOModel(system,entity),dataSet,datasource,context);
    }
    default Page<BaseData> fetchDefault(String system,String entity,String datasource,SearchContextBase context)
    {
        return fetchDefault(getDOModel(system,entity),datasource,context);
    }
    default List<BaseData> listDefault(String system,String entity,String datasource,SearchContextBase context)
    {
        return listDefault(getDOModel(system,entity),datasource,context);
    }




}
