package com.ycgis.macall.personalcenter.p.app;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.rs.macall.androidx.basemodel.utils.StringUtil;
import com.ycgis.macall.personalcenter.R;
import com.ycgis.macall.personalcenter.util.IdcardUtils;

/**
 * created by:   Macall
 * create time:  2023/10/27 15:40
 * copyright:    @ruansee.com
 * Describe:
 */
public class UserData {
    private static UserData userData;

    private String photo;
    //角色
    private String police_role;
    //职务
    private String police_post;

    //警号姓名
    private String userId;

    //警号姓名
    @Expose(serialize = true)
    private String userCode;

    @Expose(serialize = true)
    private String userName;

    @Expose(serialize = true)
    private String idCardNum;

    //用户所属机构
    @Expose(serialize = true)
    private String deptCode;
    @Expose(serialize = true)
    private String deptName;

    @Expose(serialize = true)
    private String ip;

    //所在地市代码
    @Expose(serialize = true)
    private String departmentCode;
    //所在地市名称
    @Expose(serialize = true)
    private String departmentName;

    private String phone1;
    private String phone2;


    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    //是否是省厅用户  true == 是省厅用户  || false == 地市用户
    private boolean isStUser;

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getPhoto() {
        return photo;
    }

    /**
     * 用户是否有效
     * 警号、身份号、组织机构代码 不能为空,否则返回 false
     * @return true : false
     */
    public boolean isValidOrNot() {
        if (StringUtil.isNullOrEmpty(userCode)) return false;
        if (StringUtil.isNullOrEmpty(deptCode)) return false;
        if (StringUtil.isNullOrEmpty(idCardNum)) return false;
        return true;
    }

    public String getPhone1() {
        return StringUtil.get(phone1,"暂无");
    }

    public void setPhone1(String phone1) {
        this.phone1 = phone1;
    }

    public String getPhone2() {
        return StringUtil.get(phone2,"暂无");
    }

    public void setPhone2(String phone2) {
        this.phone2 = phone2;
    }

    public String getPolice_post() {
        return StringUtil.get(police_post,"暂无");
    }

    public void setPolice_post(String police_post) {
        this.police_post = police_post;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public synchronized static UserData getUserData() {
        if (userData == null) {
            synchronized (UserData.class) {
                if (userData == null) userData = new UserData();
            }
        }
        return userData;
    }

    public static void setUserData(UserData userData) {
        UserData.userData = userData;
    }

    public String getPolice_role() {
        return StringUtil.get(police_role,"暂无");
    }

    public void setPolice_role(String police_role) {
        this.police_role = police_role;
    }

    public String getUserCode() {
        return userCode;
    }

    public void setUserCode(String userCode) {
        this.userCode = userCode;
    }

    public String getUserName() {
        return StringUtil.get(userName,"暂无");
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDeptCode() {
        return deptCode;
    }

    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
        initStUser();
    }

    public String getDeptName() {
        return StringUtil.get(deptName,"暂无");
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getDepartmentCode() {
        return departmentCode;
    }

    public void setDepartmentCode(String departmentCode) {
        this.departmentCode = departmentCode;
    }

    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public String getIdCardNum() {
        return StringUtil.get(idCardNum,"暂无");
    }

    public void setIdCardNum(String idCardNum) {
        this.idCardNum = idCardNum;
    }

    public boolean isStUser() {
        return isStUser;
    }

    public void setStUser(boolean stUser) {
        isStUser = stUser;
    }

    public void initStUser() {
        if (StringUtil.hasContent(deptCode)) {
            if (deptCode.startsWith("3400")) {
                isStUser = true;
            }
        }
    }

    public String toJson() {
        Gson gson = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .create();
        return gson.toJson(this);
    }

    /**
     * 获取错误的头像照片
     * 297548
     */
    public int getErrorPhotoByIdCardNum(){
        if (StringUtil.isNullOrEmpty(idCardNum)) return R.drawable.ic_load_imag_eerror;
        String genderByIdCard = IdcardUtils.getGenderByIdCard(idCardNum);
        if ("M".equals(genderByIdCard))return R.drawable.icon_police_man;
        if ("F".equals(genderByIdCard))return R.drawable.icon_police_woman;
        return R.drawable.ic_load_imag_eerror;
    }

}
