package com.microservices.pms.productLibrary.domain.vo;

import com.alibaba.fastjson2.JSONObject;
import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Nexus制品搜索对象
 *
 * @author otto
 * @date 2024-07-04
 */
@Data
@ApiModel("Nexus制品搜索对象")
public class NexusComponentSearchVo<T> {

    /**
     * 操作
     */
    private String action;

    /**
     * 方法
     */
    private String method;

    /**
     * 请求校验ID
     */
    private Long tid;

    /**
     * 类型
     */
    private String type;

    /**
     * 数据载体
     */
    private List<T> data;

    public static NexusComponentSearchVo<ComponentSearchVo> toRead(ComponentSearchVo componentSearchVo, Long tid) {
        NexusComponentSearchVo<ComponentSearchVo> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Browse");
        target.setMethod("read");
        target.setType("rpc");
        target.setTid(tid);
        List<ComponentSearchVo> data = new ArrayList<>();
        data.add(componentSearchVo);
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toReadAsset(String nexusRepoName, String assetId, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("readAsset");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        data.add(assetId);
        data.add(nexusRepoName);
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toReadComponent(String nexusRepoName, String componentId, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("readComponent");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        data.add(componentId);
        data.add(nexusRepoName);
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toCanDeleteFolder(String nexusRepoName, String node, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("canDeleteFolder");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        data.add(node);
        data.add(nexusRepoName);
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toCanDeleteComponent(String nexusRepoName, String componentId, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("canDeleteComponent");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", componentId);
        jsonObject.put("repositoryName", nexusRepoName);
        data.add(jsonObject.toJSONString());
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toCanDeleteAsset(String nexusRepoName, String assetId, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("canDeleteAsset");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        data.add(assetId);
        data.add(nexusRepoName);
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toDeleteAsset(String nexusRepoName, String assetId, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("deleteAsset");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        data.add(assetId);
        data.add(nexusRepoName);
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toDeleteComponent(String nexusRepoName, String componentId, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("deleteComponent");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("id", componentId);
        jsonObject.put("repositoryName", nexusRepoName);
        data.add(jsonObject.toJSONString());
        target.setData(data);
        return target;
    }

    public static NexusComponentSearchVo<String> toDeleteFolder(String nexusRepoName, String node, Long tid) {
        NexusComponentSearchVo<String> target = new NexusComponentSearchVo<>();
        target.setAction("coreui_Component");
        target.setMethod("deleteFolder");
        target.setType("rpc");
        target.setTid(tid);
        List<String> data = new ArrayList<>();
        data.add(node);
        data.add(nexusRepoName);
        target.setData(data);
        return target;
    }
}
