package kr.co.accura.wbx.spring.rbac;

import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDateTime;

@Entity
@Table(name = "wbx_user_roles",
        uniqueConstraints = @UniqueConstraint(columnNames = {"user_id", "role_id", "scope_id"}))
@Getter @Setter
@NoArgsConstructor @AllArgsConstructor @Builder
public class WbxUserRole {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

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

    @Column(name = "role_id", nullable = false)
    private Long roleId;

    @Column(name = "scope_type", length = 20)
    private String scopeType; // PROJECT, DEPARTMENT, null

    @Column(name = "scope_id")
    private Long scopeId;

    @Column(name = "granted_at")
    @Builder.Default
    private LocalDateTime grantedAt = LocalDateTime.now();
}
