package com.zhiqiyun.open.core.models.user;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zhiqiyun.open.core.enmus.PasswordType;
import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils;

import java.io.Serializable;

@Data
@TableName("user_password")
public class UserPassword implements Serializable {

    private static final long serialVersionUID = 5320982429919793484L;

    @TableId
    private String id;

    private Long uid;

    private String passwd;

    private String salt;

    private PasswordType passwordType;

    UserPassword() {
    }

    public UserPassword(Long uid, String passwd, String salt, PasswordType passwordType) {
        this.uid = uid;
        this.passwd = passwd;
        this.salt = salt;
        this.passwordType = passwordType;
    }


    public String getId() {
        if (id == null || "".equals(id.trim())) {
            id = DigestUtils.md5Hex(String.format("%s@%s", passwordType.name(), uid));
        }
        return id;
    }
}
