package com.petshop.backend.entity;

import jakarta.persistence.*;

import java.time.LocalDateTime;
import java.util.Objects;

@Entity
@Table(name = "activityLog")
public class ActivityLog {

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

    @ManyToOne
    @JoinColumn(name = "userId", nullable = false)
    private User user;

    @ManyToOne
    @JoinColumn(name = "storeId")
    private StoreLocation store;

    @Column(length = 50)
    private String usernameSnapshot;

    @Column(length = 100)
    private String fullNameSnapshot;

    @Column(length = 20)
    private String roleSnapshot;

    @Column(length = 100)
    private String storeNameSnapshot;

    @Column(nullable = false, columnDefinition = "TEXT")
    private String activity;

    @Column(nullable = false)
    private LocalDateTime logTimestamp = LocalDateTime.now();

    public ActivityLog() {
    }

    public ActivityLog(Long logId, User user, String activity, LocalDateTime logTimestamp) {
        this.logId = logId;
        this.user = user;
        this.activity = activity;
        this.logTimestamp = logTimestamp;
    }

    public Long getLogId() {
        return logId;
    }

    public void setLogId(Long logId) {
        this.logId = logId;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public StoreLocation getStore() {
        return store;
    }

    public void setStore(StoreLocation store) {
        this.store = store;
    }

    public String getUsernameSnapshot() {
        return usernameSnapshot;
    }

    public void setUsernameSnapshot(String usernameSnapshot) {
        this.usernameSnapshot = usernameSnapshot;
    }

    public String getFullNameSnapshot() {
        return fullNameSnapshot;
    }

    public void setFullNameSnapshot(String fullNameSnapshot) {
        this.fullNameSnapshot = fullNameSnapshot;
    }

    public String getRoleSnapshot() {
        return roleSnapshot;
    }

    public void setRoleSnapshot(String roleSnapshot) {
        this.roleSnapshot = roleSnapshot;
    }

    public String getStoreNameSnapshot() {
        return storeNameSnapshot;
    }

    public void setStoreNameSnapshot(String storeNameSnapshot) {
        this.storeNameSnapshot = storeNameSnapshot;
    }

    public String getActivity() {
        return activity;
    }

    public void setActivity(String activity) {
        this.activity = activity;
    }

    public LocalDateTime getLogTimestamp() {
        return logTimestamp;
    }

    public void setLogTimestamp(LocalDateTime logTimestamp) {
        this.logTimestamp = logTimestamp;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ActivityLog that = (ActivityLog) o;
        return Objects.equals(logId, that.logId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(logId);
    }

    @Override
    public String toString() {
        return "ActivityLog{" +
                "logId=" + logId +
                ", user=" + user +
                ", activity='" + activity + '\'' +
                ", logTimestamp=" + logTimestamp +
                '}';
    }
}
