package com.microservices.pms.enterprise.domain;

import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.web.domain.BaseEntity;
import com.microservices.pms.enterprise.domain.vo.GitlinkOrganizationInputVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;

/**
 * 项目管理企业对象 pms_enterprise
 * 
 * @author otto
 * @date 2023-10-10
 */
@Data
@ApiModel("企业对象")
public class PmsEnterprise extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 企业ID */
    private Long id;

    /** 企业名 */
    @ApiModelProperty(value = "企业名")
    @NotBlank
    private String enterpriseName;

    /** 企业描述 */
    @ApiModelProperty(value = "企业描述")
    private String enterpriseDescription;

    /**
     * 企业地址
     */
    @ApiModelProperty(value = "企业地址")
    private String enterpriseLocation;

    /** 企业标识 */
    @ApiModelProperty(value = "企业标识")
    private String enterpriseIdentifier;

    /** 企业头像 */
    @ApiModelProperty(value = "企业头像地址")
    private String enterpriseImage;

    /** GitLink组织ID */
    @ApiModelProperty(value = "GitLink组织ID")
    private Long gitlinkOrgId;

    /** 关联组织ID */
    @ApiModelProperty(value = "关联组织ID")
    private Long deptId;

    /** 删除标志（0代表存在 2代表删除） */
    private String delFlag;

    /**
     * gitlink访问地址
     */
    private String gitlinkUrl;

    public GitlinkOrganizationInputVo toGitlinkOrganizationInputVo(String base64Image) {
        GitlinkOrganizationInputVo target = new GitlinkOrganizationInputVo();
        target.setDescription(enterpriseDescription);
        target.setLocation(enterpriseLocation);
        target.setImage(base64Image);
        target.setNickname(enterpriseName);
        target.setName(enterpriseIdentifier);
        return target;
    }

    public GitlinkOrganizationInputVo toGitlinkOrganizationUpdateVo(PmsEnterprise pmsEnterpriseUpdate, String base64Image) {
        GitlinkOrganizationInputVo target = new GitlinkOrganizationInputVo();
        target.setName(enterpriseIdentifier);
        target.setNickname(pmsEnterpriseUpdate.getEnterpriseName() != null ? pmsEnterpriseUpdate.getEnterpriseName() : enterpriseName);
        if (StringUtils.isNotEmpty(base64Image)) {
            target.setImage(base64Image);
        }
        target.setDescription(pmsEnterpriseUpdate.getEnterpriseDescription() != null ? pmsEnterpriseUpdate.getEnterpriseDescription() : enterpriseDescription);
        target.setLocation(pmsEnterpriseUpdate.getEnterpriseLocation() != null ? pmsEnterpriseUpdate.getEnterpriseLocation() : enterpriseLocation);
        return target;
    }
}
