package com.friday.tooldriver.service.rpa.driverimpl;

import com.alibaba.fastjson.JSONObject;
import com.friday.base.common.response.DubboResult;
import com.friday.operation.api.tooldriver.dto.common.DriverBase;
import com.friday.operation.api.tooldriver.dto.rpa.*;
import com.friday.operation.api.tooldriver.service.ICapabilityDriver;
import com.friday.tooldriver.ServiceUTBase;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;

public class SmartRPATest extends ServiceUTBase {

    @Autowired
    private ICapabilityDriver rpaDriver;

    public DriverBase getDriverBase(){
        return DriverBase.builder()
                .tenantKey("2")
                .groupKey("6")
                .build();
    }
    @Test
    public void createGroup() {
        GroupDto group = new GroupDto();
        group.setName("myftp");
        group.setDescription("神码组创建测试");
        DubboResult result = rpaDriver.createGroup(getDriverBase(), group);
        System.out.println("执行结果：" + result);
        Assert.assertNotNull(result);
    }

    @Test
    public void queryGroups(){
        DubboResult<ArrayList<GroupDto>> result = rpaDriver.queryGroups(getDriverBase(), GroupFilter.groupFilterBuilder().build());
        System.out.println("执行结果" + JSONObject.toJSONString(result.getObject()));
    }

    @Test
    public void deleteGroup(){
        DubboResult<ArrayList<GroupDto>> result = rpaDriver.deleteGroupByKey(getDriverBase(), "6");
        System.out.println("执行结果" + JSONObject.toJSONString(result.getObject()));
    }

    @Test
    public void assignRobotToGroup(){
        DubboResult<GroupDto> result = rpaDriver.assignRobotToGroup(getDriverBase(), "XE2M55BVV16ZR83GQVDJ0DCMDYQZHN8Q769Z5RX97RW8WGB0RY50K0321731","6");
        System.out.println("执行结果" + JSONObject.toJSONString(result.getObject()));
    }
    @Test
    public void queryGroupByKey(){
        DubboResult<GroupDto> result = rpaDriver.queryGroupByKey(getDriverBase(), "5");
        System.out.println("执行结果" + JSONObject.toJSONString(result.getObject()));
    }

    @Test
    public void removeRobotToGroup(){
        DubboResult<GroupDto> result = rpaDriver.removeRobotFromGroup(getDriverBase(), "XE2M55BVV16ZR83GQVDJ0DCMDYQZHN8Q769Z5RX97RW8WGB0RY50K0321731","6");
        System.out.println("执行结果" + JSONObject.toJSONString(result.getObject()));
    }

    @Test
    public void queryPackages(){
        System.out.println("执行结果" + rpaDriver.queryPackages(getDriverBase(), new CodePackageFilter()));
    }


    @Test
    public void releasePackage(){
        System.out.println("执行结果" + rpaDriver.releaseProcess(getDriverBase(), ReleaseDto.builder()
                        .name("myftp")
                        .processVersion("1.0.0")
                .build()));
    }

    @Test
    public void queryReleasePackage(){
        System.out.println("执行结果" + rpaDriver.queryProcessReleases(getDriverBase(), new ReleaseFilter()));
    }

    @Test
    public void deleteReleaseProcess(){
        System.out.println("执行结果" + rpaDriver.deleteProcessReleaseByKey(getDriverBase(), "3"));
    }

    @Test
    public void uploadPackage(){
        System.out.println("执行结果" + rpaDriver.uploadPackage(getDriverBase(), CodePackageDto.builder()
                        .name("packageUploadTest0508")
                        .fileName("packageUploadTest0508.zip")
                        .fileType("code")
                        .filePath("109e2af588308b71ff553a18dd29598d_6dd76293f629d799e6faeec2feda1847_00d43f4d729a73323cddbe5829b4e5be")
                .build()));
    }

    @Test
    public void queryPackage(){
        System.out.println("执行结果" + rpaDriver.queryPackages(getDriverBase(),new CodePackageFilter()));
    }

    @Test
    public void queryPackageByKey(){
        System.out.println("执行结果" + rpaDriver.queryPackageByKey(getDriverBase(), "packageUploadTest0508:1.0.0"));
    }

    @Test
    public void deletePackageByKey(){
        System.out.println("执行结果" + rpaDriver.deletePackageByKey(getDriverBase(), "packageUploadTest0508:1.0.1"));
    }
}
