package com.warewms.service;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import com.warewms.common.entity.Filter;
import com.warewms.common.entity.Order;
import com.warewms.common.utils.PageUtils;

import java.util.List;
import java.util.Map;

public interface BaseService<M extends Model<M>> {

    List<M> findAll();

    M findById(Object... id);

    List<M> findByModel(M model);

    List<M> findByModelOrderBy(M model, String orderBy);

    M findFirstByModel(M model);

    M findFirstByModelOrderBy(M model, String orderBy);

    List<M> find(SqlPara sqlPara);

    M findFirst(SqlPara sqlPara);

    boolean deleteBatch(Object[]... ids);

    boolean deleteBatch(String[] columns, Object[]... ids);

    boolean deleteByModel(M model);

    Page<M> paginate(Integer pageNum, Integer pageSize, List<Filter> filters, Order order);

    Page<M> paginate(Integer pageNum, Integer pageSize, List<Filter> filters);

    Page<M> paginate(Integer pageNum, Integer pageSize);

    Page<M> paginate(Integer pageNum, Integer pageSize, List<Filter> filters, List<Order> orders);

    Page<M> paginate(Integer pageNum, Integer pageSize, Filter filter, List<Order> orders);

    Page<M> paginate(Integer pageNum, Integer pageSize, Filter filter, Order order);

    PageUtils queryPage(Map<String, Object> params);

    M insert(M model);

    List<M> findByFilter(Filter filter);

    List<M> findByFilters(List<Filter> filter);

    List<M> findByFilters(List<Filter> filter, List<Order> orders);

    M findFirstByFilters(List<Filter> filter, List<Order> orders);

    boolean update(M model);

    boolean delete(M model);

    /**
     * 查询list
     * @param first 分页起始（不分页传null）
     * @param count 每页行数（不分页传null）
     * @param filters
     * @param orders
     * @return
     */
    List<M> findList(Integer first, Integer count, List<Filter> filters, List<Order> orders);


}
