import exp from 'constants';
import api from './api';
import audit from '@/pages/deepseek/audit';

// Api参数类型
export type LoginApiParams = {
    userName: string,
    password: string,
    uuid: string,
    code: string|number,
};

// Api参数类型
export type JkLoginApiParams = {
    code: string,
    redirectUrl: string,
};

export type FetchAppListApiParams = {
    pageNumber: number,
    pageSize: number,
    userId: string,
    typeId: any,
    projectId: any,
    keyword: string,
};

export type FetchKnowledgeLibListApiParams = {
    pageNumber: number,
    pageSize: number,
};

export type CreateOrModifyKnowledgeLibApiParams = {
    name: string,
    embeddingId: string,
    description: string,
};

export type FetchAppIndexParams = {
    pageNumber: number,
    pageSize: number,
    userId: string,
    typeId: any,
    projectId: any,
    keyword: string,
};

export type CreateOrModifyApplicationApiParams = {
    id: string,
    name: string,  //应用名称
    desc: string,  //应用描述
    prompt: string, //应用提示语
    top_p: string, //topP
    temperature: string, //温度
    knowledge_ids: string[],
    slice_count: number,
    model: string,
    icon_color: string,
    icon_type: string,
    questionList: string[],
    // knowledge_info: {
    //     model: string,
    //     knowledge_ids: string[],
    //     slice_config_type: string,
    //     recall_method: string,
    //     slice_count: number,
    //     rerank_status: number,
    //     rerank_model_name: string,
    //     show_recall_result: boolean,
    //     recall_slice_splicing_method: string,
    // },
    //questionList: string[]
};

export type FetchDocumentLibListApiParams = {
    knowledge_id: string,
    page: number,
    size: number,
}

export type ModifyDocumentApiParams = {
    id: string,
    name: string,
    url: string,
    length: number,
    sentence_size: number,
    knowledge_type: number,
    custom_separator: string[],
    embedding_stat: number,
    word_num: number,
    parse_image: number
};

export type FetchChatHistoryListApiParams = Partial<{
    appId: string,
    pageNumber: number,
    pageSize: number,
}>;

export type ModifyDocumentSettingApiParams = {
    knowledgeId: string,
    documentId: string,
    setSlice: string,
    setAnalyze: string,
    setTabel: string,
};

export type FetchSliceListApiParams = {
    knowledge_id: string,
    document_id: string,
    text: string,
    pageNum: number,
    pageSize: number,
};

export type addAndModifySliceApiParams = {
    knowledgeId: string,
    sliceId: string,
    sliceText: string,
    documentId: string,
};

export type FetchAuditConfigLibListApiParams = {
    approver: string,
    pageNumber: number,
    pageSize: number,
};

// Api函数类型
export type CheckTokenApi = (token: string) => Promise<any>;
export type JkLoginApi = (data: JkLoginApiParams) => Promise<any>;
export type LoginApi = (data: LoginApiParams) => Promise<any>;
export type LogoutApi = () => Promise<any>;
export type FetchAppListApi = (data: FetchAppListApiParams) => Promise<any>;
export type FetchKnowledgeLibListApi = (data: FetchKnowledgeLibListApiParams) => Promise<any>;
export type FetchEmbeddingListApi = () => Promise<any>;
export type CreateKnowledgeLibApi = (data: CreateOrModifyKnowledgeLibApiParams) => Promise<any>;
export type ModifyKnowledgeLibApi = (knowledgeId: string, data: CreateOrModifyKnowledgeLibApiParams) => Promise<any>;
export type DeleteKnowledgeLibApi = (knowledgeId: string) => Promise<any>;
export type FetchKnowledgeLibDetailApi = (knowledgeId: string) => Promise<any>;
export type FetchAppIndexApi = (data: FetchAppIndexParams) => Promise<any>;
export type FetchApplicationDetailApi = (appId: string) => Promise<any>;
export type FetchModelListApi = () => Promise<any>;
export type FetchKnowledgeApiListApi = () => Promise<any>;
export type ModifyApplicationLibApi = (appId: string, data: CreateOrModifyApplicationApiParams) => Promise<any>;
export type DeleteApplicationLibApi = (appId: string) => Promise<any>;
export type CreateApplicationLibApi = (data: CreateOrModifyApplicationApiParams) => Promise<any>;
export type uploadFileLibApi = (konwledgeId: string) => Promise<any>;
export type FetchDocumentLibListApi = (data: FetchDocumentLibListApiParams) => Promise<any>;
export type FetchDocumentLibApi = (id: string) => Promise<any>;
export type ModifyDocumentLibApi = (id: string, data: ModifyDocumentApiParams) => Promise<any>;
export type DeleteDocumentLibApi = (id: string) => Promise<any>;
export type FetchApplicationListApi = () => Promise<any>;
export type FetchChatHistoryListApi = (data: FetchChatHistoryListApiParams) => Promise<any>;
export type ExportChatHistoryApi = (id: string) => Promise<any>;
export type FetchTakaiAppListApi = (data: FetchAppListApiParams) => Promise<any>;
export type FetchTakaiApplicationDetailApi = (appId: string) => Promise<any>;
export type CreateTakaiApplicationLibApi = (data: CreateOrModifyApplicationApiParams) => Promise<any>;
export type ModifyTakaiApplicationLibApi = (appId: string, data: CreateOrModifyApplicationApiParams) => Promise<any>;
export type DeleteTakaiApplicationLibApi = (appId: string) => Promise<any>;
export type FetchTakaiAppIndexApi = (data: FetchAppIndexParams) => Promise<any>;
export type FetchTakaiKnowledgeApiListApi = () => Promise<any>;
export type FetchTakaiKnowledgeLibListApi = (data: FetchKnowledgeLibListApiParams) => Promise<any>;
export type FetchTakaiKnowledgeLibDetailApi = (knowledgeId: string) => Promise<any>;
export type ModifyTakaiKnowledgeLibApi = (knowledgeId: string, data: CreateOrModifyKnowledgeLibApiParams) => Promise<any>;
export type CreateTakaiKnowledgeLibApi = (data: CreateOrModifyKnowledgeLibApiParams) => Promise<any>;
export type DeleteTakaiKnowledgeLibApi = (knowledgeId: string) => Promise<any>;
export type FetchTakaiDocumentLibListApi = (data: FetchDocumentLibListApiParams) => Promise<any>;
export type FetchTakaiDocumentLibApi = (id: string) => Promise<any>;
export type ModifyTakaiDocumentLibApi = (id: string, data: ModifyDocumentApiParams) => Promise<any>;
export type DeleteTakaiDocumentLibApi = (id: string) => Promise<any>;
export type FetchTakaiDocumentSettingLibApi = (id: string) => Promise<any>;
export type ModifyTakaiDocumentSettingLibApi = (id: string, data: ModifyDocumentSettingApiParams) => Promise<any>;
export type FetchTakaiSliceListApi = (data: FetchSliceListApiParams) => Promise<any>;
export type deleteTakaiSliceLibApi = (sliceId: string, knowledgeId: string, documentId: string) => Promise<any>;
export type FetchTakaiSliceDetailLibApi = (sliceId: string, knowledgeId: string) => Promise<any>;
export type modifyTakaiSliceInfoLibApi = (data: addAndModifySliceApiParams) => Promise<any>;
export type FetchTakaiChatHistoryListApi = (data: FetchChatHistoryListApiParams) => Promise<any>;
export type ExportTakaiChatHistoryApi = (id: string) => Promise<any>;
export type FetchTakaiApplicationListApi = (userId: string) => Promise<any>;
export type addTakaiSliceLibApi = (data: addAndModifySliceApiParams) => Promise<any>;
export type FetchTakaiAppTypeListApi = (dictType: string) => Promise<any>;
export type FetchUserInfoApi = (userId: string) => Promise<any>;
export type FetchAuditInfoLibDetailApi = (documentId: string) => Promise<any>;
export type FetchTakaiAuditConfigLibListApi = (data: FetchAuditConfigLibListApiParams) => Promise<any>;
export type ModifyTakaiAuditDocumentLibApi = (id: string, data: ModifyDocumentApiParams) => Promise<any>;
export type AuditTakaiApplicationApi = (appId: string, userId: string) => Promise<any>;
export type FetchTakaiProjectApi = () => Promise<any>;
export type FetchUserListApi = (data:any) => Promise<any>;

// token联登校验
const checkTokenApi: CheckTokenApi = async (token) => {
    return api.get(`/checkToken/${token}`);
};

// 建科登录
const jkloginApi: JkLoginApi = async (data) => {
    return api.post('/jk_code_login', data);
};

// 登录 prod-api/admin/login
const loginApi: LoginApi = async (data) => {
    // return api.post('-captchaImage/dev-api/admin/login', data);
    return api.post('/login', data);
};
// 验证码 prod-api/captchaImage
const captchaImage = async () => {
    const url = import.meta.env.VITE_ENV==='development'?'-captchaImage/captchaImage':'/captchaImage';
    return api.get(url, {});
};

// 登出
const logoutApi: LogoutApi = async () => {
    return api.post('/logout');
};

// 获取应用列表
const fetchAppListApi: FetchAppListApi = async (data) => {
    return api.post('/bigmodel/api/getApplicationList', data);
};

// 获取知识库列表
const fetchKnowledgeLibListApi: FetchKnowledgeLibListApi = async (data) => {
    return api.post('bigmodel/api/knowledgeList', data);
};

// 获取向量化模型列表
const fetchEmbeddingListApi: FetchEmbeddingListApi = async () => {
    return api.get('bigmodel/api/embedding');
};

// 创建知识库
const createKnowledgeLibApi: CreateKnowledgeLibApi = async (data) => {
    return api.post('bigmodel/api/createKnowledge', data);
};

// 修改知识库
const modifyKnowledgeLibApi: ModifyKnowledgeLibApi = async (knowledgeId, data) => {
    return api.put(`bigmodel/api/updateKnowledge/${knowledgeId}`, data);
};

// 删除知识库
const deleteKnowledgeLibApi: DeleteKnowledgeLibApi = async (knowledgeId) => {
    return api.delete(`bigmodel/api/delKnowledge/${knowledgeId}`);
};

// 获取知识库详情
const fetchKnowledgeLibDetailApi: FetchKnowledgeLibDetailApi = async (knowledgeId) => {
    return api.get(`bigmodel/api/detailKnowledge/${knowledgeId}`);
};

// 获取首页信息
const fetchIndexApi: FetchAppIndexApi = async (data) => {
    return api.post('/bigmodel/api/index', data);
};

// 获取应用详情
const fetchApplicationDetailApi: FetchApplicationDetailApi = async (appId) => {
    return api.get(`bigmodel/api/selectApplication/${appId}`);
};

// 模型列表
const fetchModelListApi: FetchModelListApi = async () => {
    return api.get('/bigmodel/api/model/list');
};

// 知识库列表
const fetchKnowledgeListApi: FetchKnowledgeApiListApi = async () => {
    // return api.get('/bigmodel/api/applicationList');
    return api.get('/bigmodel/api/knowledgeList');
};

// 编辑应用
const modifyApplicationLibApi: ModifyApplicationLibApi = async (appId, data) => {
    return api.put(`bigmodel/api/updateApplication/${appId}`, data);
};

// 删除应用
const deleteApplicationLibApi: DeleteApplicationLibApi = async (appId) => {
    return api.delete(`bigmodel/api/delApplication/${appId}`);
};

// 创建应用
const createApplicationLibApi: CreateApplicationLibApi = async (data) => {
    return api.post('bigmodel/api/createApplication', data);
};

// 上传知识文件
const uploadFileLibApi: uploadFileLibApi = async (konwledgeId) => {
    return api.post(`bigmodel/api/uploadDocument/${konwledgeId}`);
};

// 获取知识列表
const fetchDocumentLibListApi: FetchDocumentLibListApi = async (data) => {
    return api.post('bigmodel/api/documentList', data);
};

// 知识详情
const fetchDocumentLibApi: FetchDocumentLibApi = async (id) => {
    return api.get(`bigmodel/api/documentDetail/${id}`);
};

// 修改知识
const modifyDocumentApi: ModifyDocumentLibApi = async (id, data) => {
    return api.put(`bigmodel/api/updateDocument/${id}`, data);
};

// 删除知识文件
const deleteDocumentApi: DeleteDocumentLibApi = async (id) => {
    return api.delete(`bigmodel/api/delDocument/${id}`);
};

// 获取应用列表
const fetchApplicationListApi: FetchApplicationListApi = async () => {
    return api.get('bigmodel/api/application/list');
};

// 获取聊天记录列表
const fetchChatHistoryListApi: FetchChatHistoryListApi = async (data) => {
    return api.post('bigmodel/api/chatHistory/list', data);
};

// 导出聊天记录
const exportChatHistoryApi: ExportChatHistoryApi = async (id) => {
    return api.post(`bigmodel/api/dialog/export/${id}`, {}, { responseType: 'blob' });
};

// 获取takai应用列表
const fetchTakaiAppListApi: FetchTakaiAppListApi = async (data) => {
    return api.post('/deepseek/api/getApplicationList', data);
};

// 获取takai应用详情
const fetchTakaiApplicationDetailApi: FetchTakaiApplicationDetailApi = async (appId) => {
    return api.get(`/deepseek/api/selectApplication/${appId}`);
};

// 创建takai应用
const createTakaiApplicationLibApi: CreateTakaiApplicationLibApi = async (data) => {
    return api.post('/deepseek/api/createApplication', data);
};

// 编辑takai应用
const modifyTakaiApplicationLibApi: ModifyTakaiApplicationLibApi = async (appId, data) => {
    return api.put(`/deepseek/api/updateApplication/${appId}`, data);
};

// 删除takai应用
const deleteTakaiApplicationLibApi: DeleteTakaiApplicationLibApi = async (appId) => {
    return api.delete(`/deepseek/api/delApplication/${appId}`);
};

// 获取首页信息
const fetchTakaiIndexApi: FetchTakaiAppIndexApi = async (data) => {
    return api.post('/deepseek/api/index', data);
};

// takai知识库列表
const fetchTakaiKnowledgeListApi: FetchTakaiKnowledgeApiListApi = async () => {
    return api.get('/deepseek/api/knowledgeList');
};

// 获取takai知识库列表
const fetchTakaiKnowledgeLibListApi: FetchTakaiKnowledgeLibListApi = async (data) => {
    return api.post('/deepseek/api/getKnowledgeList', data);
};

// 获取takai知识库详情
const fetchTakaiKnowledgeLibDetailApi: FetchTakaiKnowledgeLibDetailApi = async (knowledgeId) => {
    return api.get(`/deepseek/api/detailKnowledge/${knowledgeId}`);
};

// 修改takai知识库
const modifyTakaiKnowledgeLibApi: ModifyTakaiKnowledgeLibApi = async (knowledgeId, data) => {
    return api.put(`/deepseek/api/updateKnowledge/${knowledgeId}`, data);
};

// 创建takai知识库
const createTakaiKnowledgeLibApi: CreateTakaiKnowledgeLibApi = async (data) => {
    return api.post('/deepseek/api/createKnowledge', data);
};

// 删除takai知识库
const deleteTakaiKnowledgeLibApi: DeleteTakaiKnowledgeLibApi = async (knowledgeId) => {
    return api.delete(`/deepseek/api/delKnowledge/${knowledgeId}`);
};

// 获取takai知识列表
const fetchTakaiDocumentLibListApi: FetchTakaiDocumentLibListApi = async (data) => {
    return api.post('/deepseek/api/documentList', data);
};

// takai知识详情
const fetchTakaiDocumentLibApi: FetchTakaiDocumentLibApi = async (id) => {
    return api.get(`/deepseek/api/documentDetail/${id}`);
};

// 修改takai知识
const modifyTakaiDocumentApi: ModifyTakaiDocumentLibApi = async (id, data) => {
    return api.put(`/deepseek/api/updateDocument/${id}`, data);
};

// 删除takai知识文件
const deleteTakaiDocumentApi: DeleteTakaiDocumentLibApi = async (id) => {
    return api.delete(`/deepseek/api/delDocument/${id}`);
};

// takai知识配置详情
const fetchTakaiDocumentSettingLibApi: FetchTakaiDocumentSettingLibApi = async (id) => {
    return api.get(`/deepseek/api/documentSetting/${id}`);
};

// 修改takai知识配置
const modifyTakaiDocumentSettingApi: ModifyTakaiDocumentSettingLibApi = async (id, data) => {
    return api.put(`/deepseek/api/updateDocumentSetting/${id}`, data);
};

// 获取takai切片列表
const fetchTakaiSliceListApi: FetchTakaiSliceListApi = async (data) => {
    return api.post(`/deepseek/api/getSliceList`, data);
};

// 获取takai切片列表
const deleteTakaiSliceApi: deleteTakaiSliceLibApi = async (sliceId, knowledgeId, documentId) => {
    return api.delete(`/deepseek/api/deleteSlice/${sliceId}/${knowledgeId}/${documentId}`);
};

// 获取takai切片详情
const fetchTakaiSliceDetailApi: FetchTakaiSliceDetailLibApi = async (sliceId, knowledgeId) => {
    return api.get(`/deepseek/api/getSliceDetail/${sliceId}/${knowledgeId}`);
};

// 修改takai切片详情
const modifyTakaiSliceInfoApi: modifyTakaiSliceInfoLibApi = async (data) => {
    return api.put(`/deepseek/api/updateSliceInfo/`, data);
};

// 获取takai聊天记录列表
const fetchTakaiChatHistoryListApi: FetchTakaiChatHistoryListApi = async (data) => {
    return api.post('/deepseek/api/chatHistory/list', data);
};

// 导出takai聊天记录
const exportTakaiChatHistoryApi: ExportTakaiChatHistoryApi = async (id) => {
    return api.post(`/deepseek/api/dialog/export/${id}`, {}, { responseType: 'blob' });
};

// 获取takai应用列表 (下拉框)
const fetchTakaiApplicationListApi: FetchTakaiApplicationListApi = async (userId) => {
    return api.get('/deepseek/api/application/list/' + userId);
};

// 新增takai切片
const addTakaiSliceApi: addTakaiSliceLibApi = async (data) => {
    return api.post(`/deepseek/api/add/slice/`, data);
};

// takai应用类型列表
const fetchTakaiAppTypeListApi: FetchTakaiAppTypeListApi = async (dictType) => {
    return api.get(`/deepseek/api/${dictType}`);
};

const fetchUserInfoApi: FetchUserInfoApi = async (userId) => {
    return api.get(`/deepseek/getInfo/${userId}`);
};
const fetchAuditInfoLibDetailApi: FetchAuditInfoLibDetailApi = async (documentId) => {
    return api.get(`/system/info/all/${documentId}`);
};


const fetchTakaiAuditConfigLibListApi: FetchTakaiAuditConfigLibListApi = async (data) => {
    return api.post('/deepseek/api/app/audit/list', data);
};

// 修改takai知识审核
const modifyTakaiAuditDocumentApi: ModifyTakaiAuditDocumentLibApi = async (id, data) => {
    return api.put(`/deepseek/api/updateDocumentAudit/${id}`, data);
};

const auditTakaiApplicationApi: AuditTakaiApplicationApi = async (appId, userId) => {
    return api.put(`/deepseek/api/audit/${appId}/${userId}`);
};

const fetchTakaiProjectApi: FetchTakaiProjectApi = async () => {
    return api.get(`/system/project/alllist?pageNum=1&pageSize=1000`);
};
// /system/user/appVipList   用户列表信息
const fetchUserListApi:FetchUserListApi = async (data:any) => {
    return api.get(`/system/user/appVipList?pageNum=${data.pageNum}&pageSize=${data.pageSize}&userName=${data.userName}&nickName=${data.nickName}&userType=${data.userType}`);
}


export const apis = {
    checkToken: checkTokenApi,
    jklogin: jkloginApi,
    login: loginApi,
    captchaImage:captchaImage,
    logout: logoutApi,
    fetchAppList: fetchAppListApi,
    fetchKnowledgeLibList: fetchKnowledgeLibListApi,
    fetchEmbeddingList: fetchEmbeddingListApi,
    createKnowledgeLib: createKnowledgeLibApi,
    modifyKnowledgeLib: modifyKnowledgeLibApi,
    deleteKnowledgeLib: deleteKnowledgeLibApi,
    fetchKnowledgeLibDetail: fetchKnowledgeLibDetailApi,
    fetchIndexCount: fetchIndexApi,
    fetchApplicationDetail: fetchApplicationDetailApi,
    fetchModelList: fetchModelListApi,
    fetchKnowledgeList: fetchKnowledgeListApi,
    modifyApplicationApi: modifyApplicationLibApi,
    deleteApplicationApi: deleteApplicationLibApi,
    createApplicationApi: createApplicationLibApi,
    uploadFileLibApi: uploadFileLibApi,
    fetchDocumentLibListApi: fetchDocumentLibListApi,
    fetchDocumentDetailLibApi: fetchDocumentLibApi,
    modifyDocumentLibApi: modifyDocumentApi,
    deleteDocumentLibApi: deleteDocumentApi,
    fetchApplicationList: fetchApplicationListApi,
    fetchChatHistoryList: fetchChatHistoryListApi,
    exportChatHistory: exportChatHistoryApi,
    fetchTakaiAppList: fetchTakaiAppListApi,
    fetchTakaiApplicationDetail: fetchTakaiApplicationDetailApi,
    createTakaiApplicationApi: createTakaiApplicationLibApi,
    modifyTakaiApplicationApi: modifyTakaiApplicationLibApi,
    deleteTakaiApplicationApi: deleteTakaiApplicationLibApi,
    fetchTakaiIndexCount: fetchTakaiIndexApi,
    fetchTakaiKnowledgeList: fetchTakaiKnowledgeListApi,
    fetchTakaiKnowledgeLibList: fetchTakaiKnowledgeLibListApi,
    fetchTakaiKnowledgeLibDetail: fetchTakaiKnowledgeLibDetailApi,
    modifyTakaiKnowledgeLib: modifyTakaiKnowledgeLibApi,
    createTakaiKnowledgeLib: createTakaiKnowledgeLibApi,
    deleteTakaiKnowledgeLib: deleteTakaiKnowledgeLibApi,
    fetchTakaiDocumentLibListApi: fetchTakaiDocumentLibListApi,
    fetchTakaiDocumentDetailLibApi: fetchTakaiDocumentLibApi,
    modifyTakaiDocumentLibApi: modifyTakaiDocumentApi,
    deleteTakaiDocumentLibApi: deleteTakaiDocumentApi,
    fetchTakaiDocumentSettingLibApi: fetchTakaiDocumentSettingLibApi,
    modifyTakaiDocumentSettingLibApi: modifyTakaiDocumentSettingApi,
    fetchTakaiSliceList: fetchTakaiSliceListApi,
    deleteTakaiSlice: deleteTakaiSliceApi,
    fetchTakaiSliceDetail: fetchTakaiSliceDetailApi,
    modifyTakaiSliceInfo: modifyTakaiSliceInfoApi,
    fetchTakaiChatHistoryList: fetchTakaiChatHistoryListApi,
    exportTakaiChatHistory: exportTakaiChatHistoryApi,
    fetchTakaiApplicationList: fetchTakaiApplicationListApi,
    addTakaiSlice: addTakaiSliceApi,
    fetchTakaiAppTypeList: fetchTakaiAppTypeListApi,
    fetchUserInfo: fetchUserInfoApi,
    fetchAuditInfoLibDetail: fetchAuditInfoLibDetailApi,
    fetchTakaiAuditConfigLibList: fetchTakaiAuditConfigLibListApi,
    modifyTakaiAuditDocumentLibApi: modifyTakaiAuditDocumentApi,
    auditTakaiApplicationLibApi: auditTakaiApplicationApi,
    fetchTakaiProjectLibApi: fetchTakaiProjectApi,
    fetchUserListApi: fetchUserListApi,
};
