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

import com.alibaba.fastjson2.JSONArray;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.utils.sign.Base64;
import lombok.Data;

/**
 * @author OTTO
 */
@Data
public class NexusDockerComponentVo {
    /**
     * 制品标识
     */
    private String id;
    /**
     * 制品名称
     */
    private String name;
    /**
     * 制品库标识
     */
    private String repository;
    /**
     * 格式
     */
    private String format;
    /**
     * 版本
     */
    private String version;
    /**
     * maven对象属性
     */
    private JSONArray assets;

    public NexusResultDataVo toNexusResultDataVo() {
        NexusResultDataVo target = new NexusResultDataVo();
        target.setId(name);
        target.setText(String.format("%s:%s", name, version));
        String composeId = Base64.base64ToDecoderString(id);
        if (StringUtils.isNotEmpty(composeId)) {
            String[] composeIds = composeId.split(":");
            target.setComponentId(composeIds[1]);
        }
        target.setLeaf(true);

        return target;
    }
}
