package com.fs.fastgptApi.service.Impl;

import com.alibaba.fastjson.JSON;
import com.fs.fastgptApi.config.FastGptApiConfig;
import com.fs.fastgptApi.param.CreateKnowledgeBaseParam;
import com.fs.fastgptApi.param.CreateTrainingUsageParam;
import com.fs.fastgptApi.param.GetKnowledgeBaseListParam;
import com.fs.fastgptApi.result.CreateTrainingUsageResult;
import com.fs.fastgptApi.result.GetKnowledgeBaseDetailResult;
import com.fs.fastgptApi.result.GetKnowledgeBaseListResult;
import com.fs.fastgptApi.result.KnowledgeBaseResult;
import com.fs.fastgptApi.service.DataSetService;
import com.fs.fastgptApi.util.HttpUtil;
import org.springframework.stereotype.Service;

/**
 * 知识库
 */
@Service
public class DataSetServiceImpl implements DataSetService {



    /**
     * 创建训练订单
     */
    @Override
    public CreateTrainingUsageResult createTrainingUsage(CreateTrainingUsageParam param,String url,String key) {
//        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.createTrainingUsage, FastGptApiConfig.Key);
        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.createTrainingUsage, key);

        CreateTrainingUsageResult result= JSON.parseObject(json, CreateTrainingUsageResult.class);
        return result;
    }

    /**
     * 创建一个知识库
     */
    @Override
    public KnowledgeBaseResult createKnowledgeBase(CreateKnowledgeBaseParam param,String url,String key) {
//        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.createKnowledgeBase, FastGptApiConfig.Key);
        String json = HttpUtil.sendPost(param, url + FastGptApiConfig.createKnowledgeBase, key);
        KnowledgeBaseResult result = JSON.parseObject(json, KnowledgeBaseResult.class);
        return result;
    }

    /**
     * 获取知识库列表
     */
    @Override
    public GetKnowledgeBaseListResult getKnowledgeBaseList(GetKnowledgeBaseListParam param,String url,String key) {
//        String json = HttpUtil.templateResultPost(param, url + FastGptApiConfig.getKnowledgeBaseList, FastGptApiConfig.Key);
        String json = HttpUtil.templateResultPost(param, url + FastGptApiConfig.getKnowledgeBaseList, key);
        GetKnowledgeBaseListResult result = JSON.parseObject(json, GetKnowledgeBaseListResult.class);
        return result;
    }

    /**
     * 获取知识库详情
     */
    @Override
    public GetKnowledgeBaseDetailResult getKnowledgeBaseDetail(String ID,String url,String key) {
//        String json = HttpUtil.sendGet(ID, url + FastGptApiConfig.getKnowledgeBaseDetail, FastGptApiConfig.Key);
        String json = HttpUtil.sendGet(ID, url + FastGptApiConfig.getKnowledgeBaseDetail, key);
        GetKnowledgeBaseDetailResult result = JSON.parseObject(json, GetKnowledgeBaseDetailResult.class);
        return result;
    }

    /**
     * 删除一个知识库
     */
    @Override
    public KnowledgeBaseResult deleteKnowledgeBase(String ID,String url,String key) {
        String json = HttpUtil.sendDelete(ID, url + FastGptApiConfig.deleteKnowledgeBase, key);
        KnowledgeBaseResult result = JSON.parseObject(json, KnowledgeBaseResult.class);
        return result;
    }



}
