package com.cm.common.plugin.service.dynamic;

import com.cm.common.exception.RemoveException;
import com.cm.common.exception.SaveException;
import com.cm.common.exception.SearchException;
import com.cm.common.exception.UpdateException;
import com.cm.common.pojo.ListPage;
import com.cm.common.result.SuccessResult;
import com.cm.common.result.SuccessResultList;

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

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: IDynamicDataService
 * @Description: 动态数据
 * @Author: WangGeng
 * @Date: 2019/12/4 16:35
 * @Version: 1.0
 **/
public interface IDynamicDataService {
    /**
     * 保存动态数据
     *
     * @param tableName
     * @param params
     * @return
     * @throws SearchException
     * @throws SaveException
     */
    SuccessResult saveDynamicData(String tableName, Map<String, Object> params) throws SearchException, SaveException;

    /**
     * 保存动态数据（APP）
     *
     * @param token
     * @param tableName
     * @param params
     * @return
     * @throws SearchException
     * @throws SaveException
     */
    SuccessResult saveDynamicData(String token, String tableName, Map<String, Object> params) throws SearchException, SaveException;

    /**
     * 删除动态数据
     *
     * @param tableName
     * @param ids
     * @return
     * @throws RemoveException
     */
    SuccessResult removeDynamicData(String tableName, String ids) throws RemoveException;

    /**
     * 删除动态数据（APP）
     *
     * @param token
     * @param tableName
     * @param ids
     * @return
     * @throws RemoveException
     */
    SuccessResult removeDynamicData(String token, String tableName, String ids) throws RemoveException;

    /**
     * 修改动态数据
     *
     * @param tableName
     * @param id
     * @param params
     * @return
     * @throws UpdateException
     */
    SuccessResult updateDynamicData(String tableName, String id, Map<String, Object> params) throws UpdateException;

    /**
     * 修改动态数据（APP）
     *
     * @param token
     * @param tableName
     * @param id
     * @param params
     * @return
     */
    SuccessResult updateDynamicData(String token, String tableName, String id, Map<String, Object> params) throws UpdateException;

    /**
     * 修改动态数据（链接）
     *
     * @param tableName
     * @param joinKey
     * @param joinId
     * @param params
     * @return
     */
    SuccessResult updateDynamicJoinData(String tableName, String joinKey, String joinId, Map<String, Object> params) throws UpdateException;

    /**
     * 修改动态数据（链接）（APP）
     *
     * @param token
     * @param tableName
     * @param joinKey
     * @param joinId
     * @param params
     * @return
     * @throws UpdateException
     */
    SuccessResult updateDynamicJoinData(String token, String tableName, String joinKey, String joinId, Map<String, Object> params) throws UpdateException;

    /**
     * 动态数据列表
     *
     * @param tableName
     * @param params
     * @return
     */
    List<Map<String, Object>> listDynamicData(String tableName, Map<String, Object> params);

    /**
     * 动态数据列表，默认
     *
     * @param tableName
     * @param params
     * @return
     */
    List<Map<String, Object>> listDynamicDataDefault(String tableName, Map<String, Object> params);

    /**
     * 分页动态数据列表
     *
     * @param tableName
     * @param listPage
     * @return
     * @throws SearchException
     */
    SuccessResultList<List<Map<String, Object>>> listPageDynamicData(String tableName, ListPage listPage) throws SearchException;

    /**
     * 动态数据详情
     *
     * @param tableName
     * @param id
     * @return
     * @throws SearchException
     */
    Map<String, Object> getDynamicData(String tableName, String id) throws SearchException;

    /**
     * 动态数据（链接）详情
     *
     * @param tableName
     * @param joinKey
     * @param joinId
     * @return
     * @throws SearchException
     */
    Map<String, Object> getDynamicJoinData(String tableName, String joinKey, String joinId) throws SearchException;

    /**
     * 动态数据详情
     *
     * @param tableName
     * @param joinKey
     * @param joinIds
     * @return
     * @throws SearchException
     */
    List<Map<String, Object>> listDynamicJoinData(String tableName, String joinKey, List<String> joinIds) throws SearchException;

    /**
     * 设置表字段为驼峰式
     *
     * @param listDynamicData
     */
    void resetDynamicDataKey2LowerUpper(List<Map<String, Object>> listDynamicData);

}
