package p.packer;

import p.packer.messages.PackerProjectContext;

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

public final class PackerWorkspacePaths {
    private static final String ASSETS_DIR = "assets";
    private static final String PROMETEU_DIR = ".prometeu";
    private static final String REGISTRY_FILE = "index.json";
    private static final String CACHE_FILE = "cache.json";

    private PackerWorkspacePaths() {
    }

    public static Path assetsRoot(PackerProjectContext project) {
        return Objects.requireNonNull(project, "project").rootPath().resolve(ASSETS_DIR).toAbsolutePath().normalize();
    }

    public static Path registryDirectory(PackerProjectContext project) {
        return assetsRoot(project).resolve(PROMETEU_DIR).toAbsolutePath().normalize();
    }

    public static Path registryPath(PackerProjectContext project) {
        return registryDirectory(project).resolve(REGISTRY_FILE).toAbsolutePath().normalize();
    }

    public static Path cachePath(PackerProjectContext project) {
        return registryDirectory(project).resolve(CACHE_FILE).toAbsolutePath().normalize();
    }

    public static Path assetRoot(PackerProjectContext project, String relativeRoot) {
        return assetsRoot(project).resolve(relativeRoot).toAbsolutePath().normalize();
    }

    public static String relativeAssetRoot(PackerProjectContext project, Path assetRoot) {
        return assetsRoot(project).relativize(assetRoot.toAbsolutePath().normalize()).toString().replace('\\', '/');
    }
}
