package com.betriebsratkanzlei.legalconsenthub.user

import com.betriebsratkanzlei.legalconsenthub_api.model.UserStatus
import jakarta.persistence.*
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.LocalDateTime

@Entity
@EntityListeners(AuditingEntityListener::class)
@Table(name = "app_user")
class User(
    @Id
    @Column(nullable = false)
    var id: String,

    @Column(nullable = false)
    var name: String,

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    var status: UserStatus = UserStatus.ACTIVE,

    @ElementCollection
    @CollectionTable(name = "user_organization_roles", joinColumns = [JoinColumn(name = "user_id")])
    var organizationRoles: MutableSet<UserOrganizationRole> = mutableSetOf(),

    @CreatedDate
    @Column(nullable = false)
    var createdAt: LocalDateTime? = null,

    @LastModifiedDate
    @Column(nullable = false)
    var modifiedAt: LocalDateTime? = null
)
