package cokr.xit.fims.cmmn;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class DirectoryStructureToJson {

	public static Node getNode(File fileNode) throws IOException{

        if(fileNode.isDirectory() || fileNode.getName().equals("files")){
            return new Node(fileNode.getName(),"directory", getDirList(fileNode));
        }else{
            return new Node(fileNode.getName(),"file",null);
        }
    }


    public static List<Node> getDirList(File node) throws IOException{
        List<Node> children=new ArrayList<>();
        for(File n : node.listFiles()){
        	children.add(getNode(n));
        }
        return children;
    }

    public static class Node {
        private String text;
        private String type;
        private List<Node> children;

        public Node() { }

        public Node(String text, String type, List<Node> children) {
            this.text = text;
            this.type = type;
            this.children = children;
        }

        public String getText() {
            return text;
        }

        public void setText(String text) {
            this.text = text;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public List<Node> getChildren() {
            return children;
        }

        public void setChildren(List<Node> children) {
            this.children = children;
        }
    }
}
