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.AccountType;
import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils;

import java.io.Serializable;

/**
 * @author Administrator
 * @date 2017-6-7
 */
@Data
@TableName("user_login_account")
public class UserLoginAccount implements Serializable {

    private static final long serialVersionUID = -6476815660455154143L;

    @TableId
    private String id;

    private Long uid;

    private String loginAccount;

    private AccountType accountType;

    public UserLoginAccount() {
    }

    public UserLoginAccount(Long uid, String loginAccount, AccountType accountType) {
        this.uid = uid;
        this.loginAccount = loginAccount;
        this.accountType = accountType;
    }

    public UserLoginAccount(String loginAccount, AccountType accountType) {
        this.loginAccount = loginAccount;
        this.accountType = accountType;
    }

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

}
