package com.qmth.sop.business.bean.dto;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.qmth.sop.common.enums.GenderEnum;
import com.qmth.sop.common.enums.RoleTypeEnum;
import com.qmth.sop.common.enums.UserRoleEnum;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

/**
 * @Description: 用户dto
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2023/8/7
 */
public class UserDto implements Serializable {

    @JsonSerialize(using = ToStringSerializer.class)
    private Long id;

    private String loginName;
    private String realName;
    private String mobileNumber;
    private Boolean enable;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long orgId;

    private String orgName;
    private GenderEnum gender;
    private String genderStr;
    private List<RoleDto> roles;

    @ApiModelProperty("是否绑定供应商")
    Boolean bandSupplier = false;

    @ApiModelProperty("用户角色（设备发货员、乙方总负责人用）")
    UserRoleEnum userRoleEnum;

    public Boolean getBandSupplier() {
        if (!CollectionUtils.isEmpty(roles)) {
            int count = (int) roles.stream().filter(s -> {
                if (s.getType() == RoleTypeEnum.DEVICE_DELIVERY) {
                    this.userRoleEnum = Objects.nonNull(userRoleEnum) ? UserRoleEnum.THIRD_PMO_AND_DEVICE_DELIVERY : UserRoleEnum.DEVICE_DELIVERY;
                } else if (s.getType() == RoleTypeEnum.THIRD_PMO) {
                    this.userRoleEnum = Objects.nonNull(userRoleEnum) ? UserRoleEnum.THIRD_PMO_AND_DEVICE_DELIVERY : UserRoleEnum.THIRD_PMO;
                }
                return Objects.nonNull(this.userRoleEnum) ? true : false;
            }).count();
            return count > 0 ? true : false;
        }
        return bandSupplier;
    }

    public UserRoleEnum getUserRoleEnum() {
        return userRoleEnum;
    }

    public void setUserRoleEnum(UserRoleEnum userRoleEnum) {
        this.userRoleEnum = userRoleEnum;
    }

    public void setBandSupplier(Boolean bandSupplier) {
        this.bandSupplier = bandSupplier;
    }

    public String getGenderStr() {
        if (Objects.nonNull(this.gender)) {
            return this.gender.getTitle();
        } else {
            return genderStr;
        }
    }

    public void setGenderStr(String genderStr) {
        this.genderStr = genderStr;
    }

    public GenderEnum getGender() {
        return gender;
    }

    public void setGender(GenderEnum gender) {
        this.gender = gender;
    }

    public List<RoleDto> getRoles() {
        return roles;
    }

    public void setRoles(List<RoleDto> roles) {
        this.roles = roles;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public String getMobileNumber() {
        return mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    public Boolean getEnable() {
        return enable;
    }

    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
}
