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

import dev.dinauer.maven.maven.core.release.ReleasePom;
import dev.dinauer.maven.maven.core.release.ReleaseVersion;
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.NotFoundException;

import java.util.Map;

@ApplicationScoped
public class SnapshotPomRepo implements PanacheRepositoryBase<SnapshotPom, String>
{
    public SnapshotPom find(SnapshotBundle bundle)
    {
        return find("snapshotBundle = :snapshotBundle", Map.ofEntries(Map.entry("snapshotBundle", bundle))).firstResult();
    }

    public SnapshotPom require(SnapshotBundle bundle)
    {
        SnapshotPom snapshotPom = find("snapshotBundle = :bundle", Map.ofEntries(Map.entry("bundle", bundle))).firstResult();
        if (snapshotPom != null)
        {
            return snapshotPom;
        }
        else
        {
            throw new NotFoundException();
        }
    }
}
