package ru.soune.nocopy.entity.violation;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.*;
import org.springframework.data.annotation.CreatedDate;
import ru.soune.nocopy.entity.file.FileEntity;
import ru.soune.nocopy.entity.search.GlobalSearchResult;

import java.time.LocalDateTime;

@Entity
@Table(name = "violation")
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Violation {

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

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

    @Column(name = "url_hash", nullable = false, unique = true, columnDefinition = "TEXT")
    private String urlHash;

    @Column(name = "page_url", columnDefinition = "TEXT")
    private String pageUrl;

    @Column(name = "title", columnDefinition = "TEXT")
    private String pageTitle;

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

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

    @CreatedDate
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdDate = LocalDateTime.now();

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "file")
    @ToString.Exclude
    @JsonIgnore
    private FileEntity fileEntity;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "global_search_result")
    @ToString.Exclude
    @JsonIgnore
    private GlobalSearchResult globalSearchResult;
}
