package test.com.pjilisense.flxai.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.ApiModelProperty;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
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.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class VoiceRefFilesControllerTest {

    @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 testGetAllAiTools() {
        String url = TestUtils.WebconnectURL+"/api/robot/voicereffiles/queryAll?language=ch";
        String charset = TestUtils.UTF8;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("language","zh");
            String body = TestUtils.doPost(url, JSON.toJSONString(params), charset);
            System.out.println(body);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //param ={"language":"zh"}
        //{"code":0,"msg":"success","data":[{"id":"1896763411581108225","name":"音色Modify","voicePath":"uploads/202503/5c799cffa5864619b817063f77fe734e.MP3","imgPath":"1896761492913520641","language":"zh"}]}
    }
    @Test
    public void testSave() {
        String url = TestUtils.WebconnectURL+"/api/robot/voicereffiles";
        String charset = TestUtils.UTF8;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("name","音色1");
            params.put("voicePath","uploads/202503/5c799cffa5864619b817063f77fe734d.MP3");
            params.put("imgPath","1896761492913520641");
            params.put("language","zh");
            params.put("voiceServerDir","A1");
            String body = TestUtils.doPost(url, JSON.toJSONString(params), charset);
            System.out.println(body);
            //param ={"voicePath":"uploads/202503/5c799cffa5864619b817063f77fe734d.MP3","imgPath":"1896761492913520641","name":"音色1","language":"zh","voiceServerDir":"A1"}
            //{"code":0,"msg":"success","data":null}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Test
    public void testupdate() {
        String url = TestUtils.WebconnectURL+"/api/robot/voicereffiles";
        String charset = TestUtils.UTF8;
        try {
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("id","1896763411581108225");
            params.put("name","音色Modify");
            params.put("voicePath","uploads/202503/5c799cffa5864619b817063f77fe734e.MP3");
            params.put("imgPath","1896761492913520641");
            params.put("language","zh");
            String body = TestUtils.doPut(url, JSON.toJSONString(params), charset);
            System.out.println(body);
            //param ={"voicePath":"uploads/202503/5c799cffa5864619b817063f77fe734e.MP3","imgPath":"1896761492913520641","name":"音色Modify","language":"zh","id":"1896763411581108225","voiceServerDir":"A1"}
            //{"code":0,"msg":"success","data":null}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
