package org.raddatz.familienarchiv.user;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.*;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@Entity
@Table(name = "user_groups")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class UserGroup {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private UUID id;

    @Column(unique = true, nullable = false)
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private String name; // z.B. "Admins", "Familie Müller"

    // Wir speichern Rechte als einfache Strings (z.B. "READ_ALL", "WRITE_DOCUMENTS")
    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "group_permissions", joinColumns = @JoinColumn(name = "group_id"))
    @Column(name = "permission")
    @Builder.Default
    @Schema(requiredMode = Schema.RequiredMode.REQUIRED)
    private Set<String> permissions = new HashSet<>();
}
