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.ProductLibraryRepositoriesFormatEnum;
import com.microservices.pms.productLibrary.domain.ProductLibraryRepositoriesTypeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 产品库操作对象
 *
 * @author otto
 * @date 2024-07-09
 */
@Data
@ApiModel("产品库操作对象")
public class ProductRepositoriesOperateVo {
    @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 = ProductLibraryRepositoriesFormatEnum.PRODUCT.getKey();
    @ApiModelProperty(value = "产品库描述")
    private String describe;


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

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