package com.rera.mss.model

import com.rera.mss.config.MEDIUM_STRING_FIELD_LENGTH
import org.hibernate.annotations.NaturalId
import javax.persistence.*

@Entity
@Table(name = "Role")
data class Role(
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        var id: Long,

        @Enumerated(EnumType.STRING)
        @NaturalId
        @Column(length = MEDIUM_STRING_FIELD_LENGTH)
        var name: Name
) {

    @OneToMany(mappedBy = "role", cascade = [CascadeType.ALL], orphanRemoval = false)
    var userRoles: MutableSet<UserRole> = mutableSetOf()

    @OneToMany(mappedBy = "role", cascade = [CascadeType.ALL], orphanRemoval = false)
    var transitionRoles: MutableSet<SysTransition> = mutableSetOf()
}

enum class Name {
    ROLE_USER,
    ROLE_ADMIN
}