package dev.dinauer.maven.maven.core;

import dev.dinauer.maven.maven.core.model.File;
import dev.dinauer.maven.maven.core.model.MavenContext;

import java.nio.file.Path;

public class MavenContextProvider
{
    public static MavenContext parse(String path)
    {
        File file = File.parse(Path.of(path).getFileName().toString());
        switch (file.getType())
        {
            case JAR, POM ->
            {
                MavenUrlParser parser = MavenUrlParser.parse(path);
                return new MavenContext(parser.groupId(), parser.artifactId(), parser.version(), file);
            }
            case XML ->
            {
                MavenMetadataUrlParser parser = MavenMetadataUrlParser.parse(path);
                return new MavenContext(parser.groupId(), parser.artifactId(), null, file);
            }
        }
        throw new RuntimeException();
    }
}
