package com.face.global.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class GlobalUser {
    private String userId;

    private String userName;

    private String userType;

    private String minOpenId;

    private String unionId;

    private String wxType;

    private Map<String, Object> otherProperties;

    public String getString(String key, String defaultValue) {
        return Optional.ofNullable(otherProperties.get(key)).map(Objects::toString).orElse(defaultValue);
    }

    public Boolean getBoolean(String key, Boolean defaultValue) {
        return Optional.ofNullable(otherProperties.get(key))
                .map(data -> Boolean.parseBoolean(data.toString()))
                .orElse(defaultValue);
    }
}
