import ink.wgink.annotation.rpc.rest.RemoteService;
import ink.wgink.annotation.rpc.rest.method.RemoteDeleteMethod;
import ink.wgink.annotation.rpc.rest.method.RemoteGetMethod;
import ink.wgink.annotation.rpc.rest.method.RemotePostMethod;
import ink.wgink.annotation.rpc.rest.method.RemotePutMethod;
import ink.wgink.annotation.rpc.rest.params.*;
import ink.wgink.common.rpc.rest.proxy.RestRemoteProxy;
import ink.wgink.pojo.dtos.user.UserDTO;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultList;

import java.io.File;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: RemoteTest
 * @Description: 远程调用
 * @Author: wanggeng
 * @Date: 2021/9/19 11:28 下午
 * @Version: 1.0
 */
public class RemoteTest {

    @RemoteService
    public interface IDemo {
        @RemoteGetMethod("/app/user-expand/get-user-release/{userId}")
        UserDTO getUser(@RemoteServerParams String remotePath, @RemotePathParams("userId") String userId);

        @RemoteGetMethod("/app/user-expand/list-user-release")
        List<UserDTO> listUser(@RemoteServerParams String remotePath);

        @RemoteGetMethod("/app/user-expand/listpage-user-release")
        SuccessResultList<List<UserDTO>> listPageUser(@RemoteServerParams String remotePath, @RemoteQueryParams("page") Integer page, @RemoteQueryParams("size") Integer size);

        @RemotePostMethod("/app/user-expand/save-release")
        SuccessResult postRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams Map<String, Object> params);

        @RemotePostMethod("/app/user-expand/save-list-release")
        SuccessResult postListRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams List<Map<String, Object>> params);

        @RemotePutMethod("/app/user-expand/update-release")
        SuccessResult putRelease(@RemoteServerParams String remotePath, @RemoteJsonBodyParams Map<String, Object> params);

        @RemoteDeleteMethod("/app/user-expand/delete-release/{userIds}")
        SuccessResult deleteRelease(@RemoteServerParams String remotePath, @RemotePathParams("userIds") String userIds);

        @RemotePostMethod("/api/file/v2/upload-file")
        String file(@RemoteServerParams String remotePath, @RemoteFileParams("file") File file);
    }

    public static void main(String[] args) {
        String remotePath = "http://127.0.0.1:7008/study";

        IDemo instance = RestRemoteProxy.getInstance(IDemo.class);
//        UserDTO userDTO = instance.getUser(remotePath, "e48e9c4a-995e-4061-abcd-a3c260c11333");
//        System.out.println(userDTO);
//        System.out.println();
//
//        List<UserDTO> userDTOs = instance.listUser(remotePath);
//        System.out.println(userDTOs.size());
//        System.out.println();
//
//        SuccessResultList<List<UserDTO>> successResultUserList = instance.listPageUser(remotePath, 1, 5);
//        System.out.println(successResultUserList.getPage());
//        System.out.println();
//
//        Map<String, Object> requestBody = new HashMap<>();
//        requestBody.put("aaa", "aaa1");
//        SuccessResult successResult = instance.postRelease(remotePath, requestBody);
//        System.out.println(successResult);
//        System.out.println();
//
//        List<Map<String, Object>> listBody = new ArrayList<>();
//        listBody.add(requestBody);
//        SuccessResult successResult1 = instance.postListRelease(remotePath, listBody);
//        System.out.println(successResult1);
//        System.out.println();
//
//        requestBody.put("aaa", "aaa2");
//        SuccessResult successResult2 = instance.putRelease(remotePath, requestBody);
//        System.out.println(successResult2);
//        System.out.println();
//
//        SuccessResult successResult3 = instance.deleteRelease(remotePath, "abc_def_ghi");
//        System.out.println(successResult3);
//        System.out.println();

        File file = new File("/Users/wanggeng/Desktop/UploadFiles/files/20220413/b92bcd7e553d4074afd4b36efc3b0899.docx");
        String file1 = instance.file(remotePath, file);
        System.out.println(file1);
    }
}
