package com.iqser.red.service.persistence.management.v1.processor.dataexchange.zipreaders;

import java.nio.file.Path;

import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.utils.FileNameUtils;

public record ZipEntryData(ZipArchiveEntry entry, byte[] data) {

    public String getFileName() {

        return Path.of(entry.getName()).getFileName().toString();
    }


    public String getParentFolder() {

        Path parent = Path.of(entry.getName()).getParent();
        if (parent == null) {
            return "";
        }
        return parent.getFileName().toString();
    }


    public boolean isInFolder(String folder) {

        Path path = Path.of(entry.getName());
        for (int i = 0; i < path.getNameCount(); i++) {
            if (path.getName(i).toFile().getName().equals(folder)) {
                return true;
            }
        }
        return false;
    }


    public String getBaseFolder() {

        Path path = Path.of(entry.getName());

        if (path.getNameCount() == 0) {
            return "";
        }
        return path.getName(0).getFileName().toString();
    }


    public int getDepth() {

        return Path.of(entry.getName()).getNameCount();
    }


    public String getExtension() {

        return FileNameUtils.getExtension(entry.getName());
    }


    public boolean isFile() {

        return !entry.isDirectory();
    }

}
