package com.izouma.nineth.domain;

import com.izouma.nineth.enums.LoginType;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.time.LocalDateTime;


@Data
@Entity
@Table(indexes = {
        @Index(columnList = "userId"),
        @Index(columnList = "phone"),
})
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("资产")
public class LoginLog extends BaseEntity {
    /**
     * 登录手机号
     */
    private String phone;
    /**
     * 登录Id
     */
    private Long userId;
    /**
     *登录时间
     */
    private LocalDateTime loginTime;
    /**
     *登录状态
     */
    private boolean loginSuccess;
    /**
     *登录IP
     */
    private String ipAddress;
    /**
     *客户端类型
     */
    private String clientType;
    /**
     * 操作系统类型
     */
    private String os;
    /**
     * 浏览器类型
     */
    private String browser;
    /**
     * 登录方式
     */
    @Enumerated(EnumType.STRING)
    private LoginType loginType;

    public LoginLog(Boolean loginSuccess,LoginType loginType,String phone,Long loginUserId) {
        this.loginSuccess = loginSuccess;
        this.loginType = loginType;
        this.phone = phone;
        this.loginTime = LocalDateTime.now();
        this.userId = loginUserId;
    }
}
