package ru.soune.nocopy.entity.monitoring;

import jakarta.persistence.*;
import lombok.*;
import ru.soune.nocopy.entity.file.FileEntity;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "file_monitoring")
public class FileMonitoringEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "file_id", nullable = false)
    private FileEntity file;

    @Column(name = "user_id", nullable = false)
    private Long userId;

    @Enumerated(EnumType.STRING)
    @Column(name = "monitoring_type", nullable = false)
    private MonitoringType monitoringType;

    @Column(name = "next_run")
    private LocalDateTime nextRun;

    @Column(name = "last_run")
    private LocalDateTime lastRun;

    @Column(name = "last_run_status")
    private String lastRunStatus;

    @Column(name = "is_active", nullable = false)
    private boolean isActive = true;

    @Column(name = "created_at", nullable = false)
    private LocalDateTime createdAt;

    @Column(name = "updated_at")
    private LocalDateTime updatedAt;

    @PrePersist
    public void prePersist() {
        this.createdAt = LocalDateTime.now();
        this.updatedAt = LocalDateTime.now();
    }

    @PreUpdate
    public void preUpdate() {
        this.updatedAt = LocalDateTime.now();
    }
}