package de.thpeetz.kontor.models.media;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Version;

@Getter
@Setter
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "media_file")
public class MediaFile {

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

    @Version
    private int version;

    @Column(name = "created_date")
    private Date createdDate;

    @Column(name = "last_modified_date")
    private Date lastModifiedDate;

    @Column(nullable = true)
    private String url;

    @Column
    private boolean review;

    @Column(name = "should_download")
    private boolean shouldDownload;

    @Column(nullable = true)
    private String title;

    @Column(name = "cloud_link", nullable = true)
    private String cloudLink;

    @Column(name = "file_name", nullable = true)
    private String fileName;

    @Column(nullable = true)
    private String path;

    @Column(nullable = true)
    @OneToMany(fetch = FetchType.EAGER, mappedBy = "media_file", cascade = CascadeType.REFRESH, orphanRemoval = true)
    List<MediaActorFile> mediaActorFiles = new LinkedList<>();

    public static MediaFile newMediaFile(String url) {
        var mediaFile = new MediaFile();
        mediaFile.setUrl(url);
        return mediaFile;
    }
}
