#define XERR
#include "zipcheck.ih"

bool ZipCheck::inspect(string const &zipName)
{
    d_dir = ".";

    fs::current_path(d_dir);                // go to the target dir

    bool hasMetadata = false;
    bool regularFiles = false;

    for (string entry: Glob{})              // inspect all its entries
    {
        if (entry == zipName)               // ignore the zip itself
            continue;

        if (Stat{ entry }.type() == Stat::DIRECTORY)    // subdirs are OK
        {
            if (isDotDir(entry))
                continue;

            exerciseDir(entry);         // inspect an exercise dir.
        }
        else if (isTextFile(entry))     // err() if not a text file
        {        
            if (entry == "metadata.txt")    // other files: not OK
                hasMetadata = true;
            else
                regularFiles = true;
        }
    }       

    if (not hasMetadata)
        err() << "no metadata.txt file in the top-level directory\n";

    if (regularFiles)
        err() << "unexpected file(s) in the top-level directory\n";
    
    return ok();
}
