package dev.rheinsw.gateway.model;

import dev.rheinsw.shared.entity.BaseEntity;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Set;

/**
 * @author Thatsaphorn Atchariyaphap
 * @since 25.04.25
 */
@Entity
@Table(name = "api_key")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ApiKey extends BaseEntity {

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

    @Column(name = "api_key", unique = true, nullable = false)
    private String apiKey;

    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private ApiKeyType type;

    @ElementCollection(fetch = FetchType.EAGER)
    @CollectionTable(name = "api_key_services", joinColumns = @JoinColumn(name = "api_key_id"))
    @Column(name = "allowed_service")
    private Set<String> allowedServices;

    @Column(nullable = false)
    private boolean enabled;

    @Column(name = "frontend_only", nullable = false)
    private boolean frontendOnly;

    @Column
    private String description;
}
