package com.microservices.zone.dataset.domain.vo;

import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.utils.html.EscapeUtil;
import com.microservices.zone.project.domain.vo.ZoneProjectDataVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("项目聚合数据对象")
public class ZoneDataSetProjectVo {
    @ApiModelProperty(value = "数据集名称")
    private String dataSetName;
    @ApiModelProperty(value = "数据集描述")
    private String dataSetDescription;
    @ApiModelProperty(value = "项目聚合Id")
    private Long id;
    @ApiModelProperty(value = "代码库Id")
    private Long repositoryId;
    @ApiModelProperty(value = "代码库名称")
    private String repositoryName;
    @ApiModelProperty(value = "代码库标识")
    private String repositoryFullName;
    @ApiModelProperty(value = "代码库地址")
    private String repositoryUrl;
    @ApiModelProperty(value = "项目数据集地址")
    private String dataSetUrl;

    public ZoneDataSetProjectVo() {
    }

    public ZoneDataSetProjectVo(ZoneProjectDataVo projectDataVo, String gitLinkUrl) {
        this.id = projectDataVo.getId();
        JSONObject projectProperties = projectDataVo.getProjectProperties();
        if (projectProperties != null) {
            if (projectProperties.containsKey("name")) {
                this.repositoryName = projectProperties.getString("name");
            }
            if (projectProperties.containsKey("fullName")) {
                this.repositoryFullName = projectProperties.getString("fullName");
                this.repositoryUrl = EscapeUtil.removeExtraSlashOfUrl(String.format("%s/%s", gitLinkUrl, this.repositoryFullName));
                this.dataSetUrl = EscapeUtil.removeExtraSlashOfUrl(String.format("%s/dataset", this.repositoryUrl));
            }
            if (projectProperties.containsKey("repositoryId")) {
                this.repositoryId = projectProperties.getLong("repositoryId");
            }
        }
    }
}
