package com.mvrent.carrental.model;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDateTime;

/** An immutable record of a significant action — who did what, when. */
@Entity
@Table(name = "audit_logs", indexes = {
        @Index(name = "idx_audit_created", columnList = "createdAt"),
        @Index(name = "idx_audit_username", columnList = "username")
})
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AuditLog {

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

    @CreationTimestamp
    private LocalDateTime createdAt;

    private String username;

    private String role;

    /** CREATE, UPDATE, DELETE, GENERATE, LOGIN_SUCCESS, LOGIN_FAILURE, … */
    private String action;

    /** The kind of thing acted on (Car, Driver, Booking, …). */
    private String entityType;

    private String entityId;

    @Column(length = 500)
    private String detail;

    private String ip;
}
