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

import com.microservices.common.core.enums.SystemRole;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.system.api.domain.SimpleSysRole;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author otto
 */

@Data
@ApiModel("GitLink用户升级为企业用户对象")
public class GitLinkUserToEnterpriseVo extends GitLinkUserSimpleInfoVo {
    @ApiModelProperty(value = "初始角色")
    private SimpleSysRole role;

    /**
     * 判断是否为更大的权限
     *
     * @return 结果
     */
    public boolean greaterAuth(String authorize) {
        if (StringUtils.isEmpty(authorize)) {
            return false;
        }
        if (this.role == null) {
            return true;
        }
        String roleKey = role.getRoleKey();
        switch (authorize) {
            case "owner": {
                return !roleKey.equals(SystemRole.PMS_ORG_ADMIN.getRoleKey());
            }
            case "admin": {
                return !roleKey.equals(SystemRole.PMS_ORG_ADMIN.getRoleKey()) && !roleKey.equals(SystemRole.PMS_PROJECT_MANAGER.getRoleKey());
            }
            default: {
                return false;
            }
        }
    }
}
