package dev.dinauer.maven.maven.core.snapshot;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import dev.dinauer.maven.maven.core.ArtifactId;
import dev.dinauer.maven.maven.core.Version;
import jakarta.persistence.*;

import java.util.List;

@Entity
@Table(name = "snapshot_version")
public class SnapshotVersion implements Version
{
    @Id
    @GeneratedValue(strategy = GenerationType.UUID)
    private String id;

    private String version;

    @ManyToOne(cascade = CascadeType.PERSIST)
    @JoinColumn(name = "artifact_id")
    @JsonBackReference
    private ArtifactId artifact;

    @OneToMany(mappedBy = "snapshotVersion")
    @JsonManagedReference
    private List<SnapshotBundle> snapshotBundles;

    public String getId()
    {
        return id;
    }

    public SnapshotVersion setId(String id)
    {
        this.id = id;
        return this;
    }

    public String getVersion()
    {
        return version;
    }

    public SnapshotVersion setVersion(String version)
    {
        this.version = version;
        return this;
    }

    public ArtifactId getArtifact()
    {
        return artifact;
    }

    public SnapshotVersion setArtifact(ArtifactId artifact)
    {
        this.artifact = artifact;
        return this;
    }

    public List<SnapshotBundle> getSnapshotBundles()
    {
        return snapshotBundles;
    }

    public SnapshotVersion setSnapshotBundles(List<SnapshotBundle> snapshotBundles)
    {
        this.snapshotBundles = snapshotBundles;
        return this;
    }

    @Override
    public boolean isSnapshot()
    {
        return true;
    }
}
