package cn.reghao.tnb.auth.app.model.po;

import cn.reghao.jutil.jdk.web.db.BaseObject;
import lombok.*;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;

/**
 * 用户登入日志
 *
 * @author reghao
 * @date 2022-07-08 10:27:55
 */
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@Setter
@Getter
public class UserLogin extends BaseObject<Integer> {
    @NotBlank
    @Size(min = 1, max = 32)
    private String loginId;
    @NotNull
    private Long userId;
    @NotNull
    private Integer loginType;
    @NotNull
    private Integer plat;
    @NotNull
    private Long loginAt;
    // 点分十进制的 IPv4 地址
    @NotBlank
    @Size(min = 7, max = 16)
    private String loginIp;
    @NotBlank
    @Size(min = 1, max = 255)
    private String userAgent;
    @NotNull
    private Boolean rememberMe;
    @NotNull
    private Boolean success;

    public UserLogin(String loginId, long userId, int plat, String loginIp,
                     int loginType, String userAgent, boolean rememberMe) {
        this.loginId = loginId;
        this.userId = userId;
        this.loginType = loginType;
        this.plat = plat;
        this.loginAt = System.currentTimeMillis();
        this.loginIp = loginIp;
        this.userAgent = userAgent;
        this.rememberMe = rememberMe;
        this.success = true;
    }
}
