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.Table;
import jakarta.persistence.Index;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * Entité représentant l'historique des synchronisations avec Keycloak.
 */
@Entity
@Table(name = "sync_history", indexes = {
        @Index(name = "idx_sync_realm", columnList = "realm_name"),
        @Index(name = "idx_sync_date", columnList = "sync_date")
})
@Data
@EqualsAndHashCode(callSuper = true)
public class SyncHistoryEntity extends PanacheEntity {

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

    @Column(name = "sync_date", nullable = false)
    private LocalDateTime syncDate;

    // USER ou ROLE
    @Column(name = "sync_type", nullable = false)
    private String syncType;

    @Column(name = "status", nullable = false) // SUCCESS, FAILURE
    private String status;

    @Column(name = "items_processed")
    private Integer itemsProcessed;

    @Column(name = "duration_ms")
    private Long durationMs;

    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;

    public SyncHistoryEntity() {
        this.syncDate = LocalDateTime.now();
    }
}
