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

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.utils.bean.BeanUtils;
import com.microservices.pms.productLibrary.domain.PmsProductLibraryRepositories;
import com.microservices.pms.productLibrary.domain.ProductLibraryRepositoriesTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;

/**
 * 制品库-仓库对象 pms_product_library_repositories
 *
 * @author otto
 * @date 2024-06-20
 */
@Data
@ApiModel("托管制品库操作对象")
public class HostedRepositoriesOperateVo {
    @ApiModelProperty(value = "制品库Id", hidden = true)
    private Long id;
    @ApiModelProperty(value = "制品库名称")
    private String alias;
    @ApiModelProperty(value = "制品库标识", hidden = true)
    private String name;
    @ApiModelProperty(value = "组织标识", hidden = true)
    private String enterpriseIdentifier;
    @ApiModelProperty(value = "制品库类型", hidden = true)
    private String type = ProductLibraryRepositoriesTypeEnum.HOSTED.getKey();
    @ApiModelProperty(value = "制品库格式", hidden = true)
    private String format;
    @ApiModelProperty(value = "是否在线", hidden = true)
    private Boolean online = true;
    @ApiModelProperty(value = "Maven制品库输入对象", hidden = true)
    private NexusRepoMavenVo maven = new NexusRepoMavenVo();
    @Valid
    @ApiModelProperty(value = "Docker制品库输入对象")
    private NexusRepoDockerVo docker;

    public PmsProductLibraryRepositories toPmsProductLibraryRepositories() {
        PmsProductLibraryRepositories pmsProductLibraryRepositories = new PmsProductLibraryRepositories();
        BeanUtils.copyProperties(this, pmsProductLibraryRepositories);
        JSONObject attributeJson = new JSONObject();
        attributeJson.put("online", online);
        attributeJson.put("maven", maven);
        attributeJson.put("docker", docker);
        pmsProductLibraryRepositories.setAttributes(attributeJson.toJSONString());
        return pmsProductLibraryRepositories;
    }

    public NexusHostedRepoInputVo toNexusRepoDataVo() {
        NexusHostedRepoInputVo target = new NexusHostedRepoInputVo();
        BeanUtils.copyProperties(this, target);
        target.setName(PmsProductLibraryRepositories.getNexusRepositoriesName(this.enterpriseIdentifier, this.name));
        target.setCleanup(new NexusRepoCleanupVo());
        target.setStorage(new NexusRepoStorageVo());
        return target;
    }
}
