package com.spring.domain.user.entity;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "APP_USER")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AppUser {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "USER_ID", nullable = false)
    private Long userId;

    @Column(name = "LOGIN_ID", nullable = false, length = 50)
    private String loginId;

    @Column(name = "PASSWORD", nullable = false, length = 128)
    private String password;

    @Column(name = "USER_NAME", nullable = false, length = 50)
    private String userName;

    @OneToMany(mappedBy = "appUser", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<AppUserRoleMap> appUserRoleMap;

    @Builder
    public AppUser(String loginId, String password, String userName, Set<AppUserRoleMap> appUserRoleMap) {
        this.loginId = loginId;
        this.password = password;
        this.userName = userName;
        this.appUserRoleMap = appUserRoleMap;
    }

}
