package com.spring.domain.user.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.Table;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "APP_USER_ROLE_MAP")
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AppUserRoleMap {

    @EmbeddedId
    private AppUserRoleMapId id;

    @ManyToOne
    @MapsId("roleId")
    @JoinColumn(name = "ROLE_ID")
    private AppUserRole appUserRole;

    @ManyToOne
    @MapsId("userId")
    @JoinColumn(name = "USER_ID")
    private AppUser appUser;
    
    @Embeddable
    @EqualsAndHashCode
    @Getter
    public static class AppUserRoleMapId implements Serializable {
        @Column(name = "ROLE_ID", nullable = false)
        private Long roleId;

        @Column(name = "USER_ID", nullable = false)
        private Long userId;
    }

}
