package com.zhongshu.card.client.model.org;

import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.base.SuperModel;
import com.zhongshu.card.client.model.org.role.RoleModel;
import com.zhongshu.card.client.model.school.DictInfoSimpleModel;
import com.zhongshu.card.client.type.CertificateType;
import com.zhongshu.card.client.type.OrganizationUserType;
import com.zhongshu.card.client.type.Sex;
import com.zhongshu.card.client.type.UserState;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 机构用户详情
 *
 * @author TRX
 * @date 2024/6/6
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class OrganizationUserModel extends SuperModel {

    @Schema(description = "机构信息")
    private OrganizationMiniModel organization;

    private String organizationName;

    public String getOrganizationName() {
        if (organization != null) {
            return organization.getName();
        }
        return "";
    }

    @Schema(description = "用户信息")
    private UserCountSimpleModel user;

    @Schema(description = "性别")
    private Sex sex;

    public Sex getSex() {
        if (user != null) {
            return user.getSex();
        }
        return null;
    }

    @Schema(description = "性别显示字段")
    private String sexStr;

    public String getSexStr() {
        if (user != null) {
            return user.getSexStr();
        }
        return "";
    }

    @Schema(description = "用户ID")
    private String userId;

    public String getUserId() {
        if (user != null) {
            return user.getUserId();
        }
        return userId;
    }

    @Schema(description = "工号、编码")
    private String code;

    @Schema(description = "用户手机号")
    private String phone;

    public String getPhone() {
        if (user != null) {
            return user.getPhone();
        }
        return phone;
    }

    @Schema(description = "姓名")
    private String name;

    public String getName() {
        if (ObjectUtils.isNotEmpty(user)) {
            return user.getName();
        }
        return name;
    }

    @Schema(description = "真实姓名")
    private String realName;

    public String getRealName() {
        if (user != null) {
            return user.getRealName();
        }
        return getName();
    }

    @Schema(description = "用户状态")
    private UserState state = UserState.Normal;

    @Schema(description = "状态名称")
    private String stateStr;

    public String getStateStr() {
        if (state != null) {
            return state.getRemark();
        }
        return "";
    }

    @Schema(description = "是否是企业管理员")
    private Boolean isAdmin = Boolean.FALSE;

    @Schema(description = "机构类型")
    private AuthType authType = AuthType.Enterprise;

    @Schema(description = "用户在机构的类型")
    private OrganizationUserType userType;

    private String userTypeStr;

    public String getUserTypeStr() {
        if (userType != null) {
            return userType.getRemark();
        }
        return "";
    }

    @Schema(description = "证件类型")
    private CertificateType certificateType = CertificateType.IDCard;

    private String certificateTypeStr;

    public String getCertificateTypeStr() {
        if (certificateType != null) {
            return certificateType.getRemark();
        }
        return "";
    }

    @Schema(description = "证件号码")
    private String cardNumber;

    @Schema(description = "职位")
    private DictInfoSimpleModel position;

    @Schema(description = "职位名称")
    private String positionName;

    public String getPositionName() {
        if (position != null) {
            return position.getName();
        }
        return "";
    }

    @Schema(description = "人脸照片")
    private List<String> faceImages;

    @Schema(description = "角色信息")
    private List<RoleModel> roles = new ArrayList<>();

    @Schema(description = "角色-人员类型名称")
    private String roleNames;

    public String getRoleNames() {
        if (ObjectUtils.isNotEmpty(roles)) {
            List<String> strs = roles.stream().map(it -> it.getName()).collect(Collectors.toList());
            return String.join("、", strs);
        }
        return "";
    }

    @Schema(description = "部门信息")
    private DepartmentModel department;

    @Schema(description = "部门名称")
    private String departmentName;

    public String getDepartmentName() {
        if (department != null) {
            return department.getName();
        }
        return "";
    }

    @Schema(description = "部门信息所有级")
    private List<DepartmentModel> departments = new ArrayList<>();
}
