package dev.lions.user.manager.server.impl.entity;

import io.quarkus.hibernate.orm.panache.PanacheEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * Snapshot local d'un utilisateur Keycloak synchronisé.
 * Permet de conserver un état minimal pour des rapports ou vérifications de cohérence.
 */
@Entity
@Table(name = "synced_user", indexes = {
        @Index(name = "idx_synced_user_realm", columnList = "realm_name"),
        @Index(name = "idx_synced_user_realm_kc_id", columnList = "realm_name,keycloak_id", unique = true)
})
@Data
@EqualsAndHashCode(callSuper = true)
public class SyncedUserEntity extends PanacheEntity {

    @Column(name = "realm_name", nullable = false)
    private String realmName;

    @Column(name = "keycloak_id", nullable = false)
    private String keycloakId;

    @Column(name = "username", nullable = false)
    private String username;

    @Column(name = "email")
    private String email;

    @Column(name = "enabled")
    private Boolean enabled;

    @Column(name = "email_verified")
    private Boolean emailVerified;

    @Column(name = "created_at")
    private LocalDateTime createdAt;
}

