/**
 * Copyright (c) 2018 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package test.com.pjilisense.flxai.controller;

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import test.com.pjilisense.flxai.TestUtils;

import java.util.HashMap;
import java.util.Map;

public class FilesControllerTest {
    @BeforeEach
    public void setUpTestDataWithinTransaction() {
        // set up test data within the transaction
    }
    @AfterEach
    public void tearDownWithinTransaction() {
        // execute "tear down" logic within the transaction
    }

    @Test
    public void testGetFileList() {
        String url = TestUtils.WebconnectURL+"/api/robot/files/file_2FbUmaefz5b4";
        String charset = TestUtils.UTF8;
        try {
            String body = TestUtils.doGet(url, charset);
            System.out.println(body);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //method =GET
        //{"code":0,"msg":"success","data":{"id":"file_2FbUmaefz5b4","userId":"fd8ae359-64dc-4a57-ab41-5438e2fda975","fileType":"text/plain","name":"jykc2.sql","size":1864714,"url":"files/482454/d2b0edb3-15bf-4fe6-ba2e-97b5f1fe0288.sql","metadata":{"date":"482454","path":"files/482454/d2b0edb3-15bf-4fe6-ba2e-97b5f1fe0288.sql","filename":"d2b0edb3-15bf-4fe6-ba2e-97b5f1fe0288.sql","dirname":"files/482454"},"createdAt":"2025-01-14 14:29:02","updatedAt":"2025-01-14 14:29:23","fileHash":"1d66edbc0b5da3289ecea1ae00ac384b2378603193574c5f0bc9a9a988de2a16","chunkTaskId":"ab3f259e-775a-4c57-8338-b273684f70d1","embeddingTaskId":"12020d55-d453-46d7-a8c8-b0bba5f5c747","accessedAt":"2025-01-14 14:29:02","fileCategory":"1","fileStatus":"1"}}
    }
//    @Test
//    public void testsave() {
//        String url = TestUtils.WebconnectURL+"/api/robot/files/";
//        String charset = TestUtils.UTF8;
//        try {
//            Map<String, Object> params = new HashMap<String, Object>();
//            params.put("userId","fd8ae359-64dc-4a57-ab41-5438e2fda975");
//            params.put("fileType","text/plain");
//            params.put("name","jykc3.sql");
//            params.put("size",1864714);
//            params.put("url","files/482454/d2b0edb3-15bf-4fe6-ba2e-97b5f1fe0288.sql");
//            params.put("fileHash","1d66edbc0b5da3289ecea1ae00ac384b2378603193574c5f0bc9a9a988de2a16");
//            params.put("chunkTaskId","ab3f259e-775a-4c57-8338-b273684f70d1");
//            params.put("embeddingTaskId","12020d55-d453-46d7-a8c8-b0bba5f5c747");
//            params.put("fileCategory","1");
//            params.put("fileStatus","1");
//
//            Map<String, Object> metadata = new HashMap<String, Object>();
//            params.put("metadata",metadata);
//            metadata.put("date","482454");
//            metadata.put("path","files/482454/d2b0edb3-15bf-4fe6-ba2e-97b5f1fe0288.sql");
//            metadata.put("filename","d2b0edb3-15bf-4fe6-ba2e-97b5f1fe0288.sql");
//            metadata.put("dirname","files/482454");
//
//            String body = TestUtils.doPost(url, JSON.toJSONString(params), charset);
//            System.out.println(body);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
    @Test
    public void testmodifyFileName() {
        String url = TestUtils.WebconnectURL+"/api/robot/files/modifyFileName";
        String charset = TestUtils.UTF8;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("id","file_2FbUmaefz5b4");
            params.put("name","jykc2.sql");
            String body = TestUtils.doPost(url, JSON.toJSONString(params), charset);
            System.out.println(body);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //method =POST
        //param ={"name":"jykc2.sql","id":"file_2FbUmaefz5b4"}
        //{"code":0,"msg":"success","data":true}
    }

    @Test
    public void testmodifyFileStatus() {
        String url = TestUtils.WebconnectURL+"/api/robot/files/modifyFileStatus";
        String charset = TestUtils.UTF8;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("id","file_2FbUmaefz5b4");
            params.put("fileStatus","1");
            String body = TestUtils.doPost(url, JSON.toJSONString(params), charset);
            System.out.println(body);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //method =POST
        //param ={"fileStatus":"1","id":"file_2FbUmaefz5b4"}
        //{"code":0,"msg":"success","data":true}
    }
    @Test
    public void testmodifyFileCategory() {
        String url = TestUtils.WebconnectURL+"/api/robot/files/modifyFileCategory";
        String charset = TestUtils.UTF8;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("id","file_2FbUmaefz5b4");
            params.put("fileCategory","1");
            String body = TestUtils.doPost(url, JSON.toJSONString(params), charset);
            System.out.println(body);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //method =POST
        //param ={"fileCategory":"1","id":"file_2FbUmaefz5b4"}
        //{"code":0,"msg":"success","data":true}
    }
}