package p.packer.testing;

import java.net.URL;
import java.nio.file.Path;
import java.util.Objects;

public final class PackerFixtureLocator {
    private PackerFixtureLocator() {
    }

    public static Path fixtureRoot(String relativePath) {
        final String normalized = Objects.requireNonNull(relativePath, "relativePath").replace('\\', '/');
        final URL resource = PackerFixtureLocator.class.getClassLoader().getResource("fixtures/" + normalized);
        if (resource == null) {
            throw new IllegalArgumentException("fixture not found: " + normalized);
        }
        try {
            return Path.of(resource.toURI()).toAbsolutePath().normalize();
        } catch (Exception exception) {
            throw new IllegalStateException("unable to resolve fixture: " + normalized, exception);
        }
    }
}
