package it.sw.pa.comune.artegna.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import it.sw.pa.comune.artegna.domain.enumeration.AzioneAudit;
import it.sw.pa.comune.artegna.domain.enumeration.TipoEntita;
import jakarta.persistence.*;
import java.io.Serial;
import java.io.Serializable;
import java.time.Instant;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * A AuditLog.
 */
@Entity
@Table(name = "audit_log")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@SuppressWarnings("common-java:DuplicatedBlocks")
public class AuditLog implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    @Column(name = "id")
    private Long id;

    @Enumerated(EnumType.STRING)
    @Column(name = "entita_tipo")
    private TipoEntita entitaTipo;

    @Column(name = "entita_id")
    private Long entitaId;

    @Enumerated(EnumType.STRING)
    @Column(name = "azione")
    private AzioneAudit azione;

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

    @Column(name = "ip_address")
    private String ipAddress;

    @Column(name = "created_at")
    private Instant createdAt;

    @ManyToOne(fetch = FetchType.LAZY)
    @JsonIgnoreProperties(value = { "internalUser", "liberatories" }, allowSetters = true)
    private UtenteApp utente;

    // jhipster-needle-entity-add-field - JHipster will add fields here

    public Long getId() {
        return this.id;
    }

    public AuditLog id(Long id) {
        this.setId(id);
        return this;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public TipoEntita getEntitaTipo() {
        return this.entitaTipo;
    }

    public AuditLog entitaTipo(TipoEntita entitaTipo) {
        this.setEntitaTipo(entitaTipo);
        return this;
    }

    public void setEntitaTipo(TipoEntita entitaTipo) {
        this.entitaTipo = entitaTipo;
    }

    public Long getEntitaId() {
        return this.entitaId;
    }

    public AuditLog entitaId(Long entitaId) {
        this.setEntitaId(entitaId);
        return this;
    }

    public void setEntitaId(Long entitaId) {
        this.entitaId = entitaId;
    }

    public AzioneAudit getAzione() {
        return this.azione;
    }

    public AuditLog azione(AzioneAudit azione) {
        this.setAzione(azione);
        return this;
    }

    public void setAzione(AzioneAudit azione) {
        this.azione = azione;
    }

    public String getDettagli() {
        return this.dettagli;
    }

    public AuditLog dettagli(String dettagli) {
        this.setDettagli(dettagli);
        return this;
    }

    public void setDettagli(String dettagli) {
        this.dettagli = dettagli;
    }

    public String getIpAddress() {
        return this.ipAddress;
    }

    public AuditLog ipAddress(String ipAddress) {
        this.setIpAddress(ipAddress);
        return this;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

    public Instant getCreatedAt() {
        return this.createdAt;
    }

    public AuditLog createdAt(Instant createdAt) {
        this.setCreatedAt(createdAt);
        return this;
    }

    public void setCreatedAt(Instant createdAt) {
        this.createdAt = createdAt;
    }

    public UtenteApp getUtente() {
        return this.utente;
    }

    public void setUtente(UtenteApp utenteApp) {
        this.utente = utenteApp;
    }

    public AuditLog utente(UtenteApp utenteApp) {
        this.setUtente(utenteApp);
        return this;
    }

    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof AuditLog)) {
            return false;
        }
        return getId() != null && getId().equals(((AuditLog) o).getId());
    }

    @Override
    public int hashCode() {
        // see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
        return getClass().hashCode();
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "AuditLog{" +
            "id=" + getId() +
            ", entitaTipo='" + getEntitaTipo() + "'" +
            ", entitaId=" + getEntitaId() +
            ", azione='" + getAzione() + "'" +
            ", dettagli='" + getDettagli() + "'" +
            ", ipAddress='" + getIpAddress() + "'" +
            ", createdAt='" + getCreatedAt() + "'" +
            "}";
    }
}
