package com.fs.fastgptApi.service.Impl;

import com.alibaba.fastjson.JSON;
import com.fs.fastgptApi.config.FastGptApiConfig;
import com.fs.fastgptApi.param.AddDataToCollectionBatchParam;
import com.fs.fastgptApi.param.GetCollectionDataListParam;
import com.fs.fastgptApi.param.SearchTestParam;
import com.fs.fastgptApi.param.UpdateCollectionDataParam;
import com.fs.fastgptApi.result.*;
import com.fs.fastgptApi.service.DataSetDataService;
import com.fs.fastgptApi.util.HttpUtil;
import org.springframework.stereotype.Service;

/**
 * 数据
 */
@Service
public class DataSetDataServiceImpl implements DataSetDataService {


    /**
     * 为集合批量添加添加数据
     */
    @Override
    public AddDataToCollectionBatchResult addDataToCollectionBatch(AddDataToCollectionBatchParam param,String url,String key) {
//        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.addDataToCollection, FastGptApiConfig.Key);
        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.addDataToCollection, key);
        AddDataToCollectionBatchResult result = JSON.parseObject(json, AddDataToCollectionBatchResult.class);
        return result;
    }

    /**
     * 获取集合的数据列表
     */
    @Override
    public GetCollectionDataListResult getCollectionDataList(GetCollectionDataListParam param,String url,String key) {
//        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.getCollectionDataList, FastGptApiConfig.Key);
        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.getCollectionDataList, key);
        GetCollectionDataListResult result = JSON.parseObject(json, GetCollectionDataListResult.class);
        return result;
    }

    /**
     *  获取单条数据详情
     */
    @Override
    public GetCollectionDataDetailResult getCollectionDataDetail(String id,String url,String key) {
//        String json = HttpUtil.sendGet(id, url + FastGptApiConfig.getCollectionDataDetail, FastGptApiConfig.Key);
        String json = HttpUtil.sendGet(id, url + FastGptApiConfig.getCollectionDataDetail, key);
        GetCollectionDataDetailResult result = JSON.parseObject(json, GetCollectionDataDetailResult.class);
        return result;
    }

    /**
     * 修改单条数据
     */
    @Override
    public KnowledgeBaseResult updateCollectionData(UpdateCollectionDataParam param,String url,String key) {
//        String json = HttpUtil.sendPut(param, url + FastGptApiConfig.updateCollectionData, FastGptApiConfig.Key);
        String json = HttpUtil.sendPut(param, url + FastGptApiConfig.updateCollectionData, key);
        KnowledgeBaseResult result = JSON.parseObject(json, KnowledgeBaseResult.class);
        return result;
    }

    /**
     * 删除单条数据 数据的id
     */
    @Override
    public KnowledgeBaseResult deleteCollectionData(String id,String url,String key) {
//        String json = HttpUtil.sendDelete(id, url + FastGptApiConfig.deleteCollectionData, FastGptApiConfig.Key);
        String json = HttpUtil.sendDelete(id, url + FastGptApiConfig.deleteCollectionData, key);
        KnowledgeBaseResult result = JSON.parseObject(json, KnowledgeBaseResult.class);
        return result;
    }

    /**
     * 搜索测试
     */
    @Override
    public SearchTestResult searchTest(SearchTestParam param,String url,String key) {
//        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.searchTest, FastGptApiConfig.Key);
        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.searchTest, key);
        SearchTestResult result = JSON.parseObject(json, SearchTestResult.class);
        return result;
    }
}
