#include <iostream>
#include <filesystem>

#include "argparse.hpp"
#include "generator.hpp"
#include "version.hpp"




int main(int argc, char* argv[]) {
    try {
        Args args = parse_args(argc, argv);
        
        // Handle version request (output only version)
        if (args.version) {
            std::cout << VERSION << std::endl;
            return 0;
        }
        
        // Show version for normal operations (unless silent)
        if (!args.silent) {
            std::cout << "Dehydrate version " << VERSION << std::endl;
        }
        
        std::filesystem::path src(args.source);
        if (!std::filesystem::exists(src)) {
            std::cerr << "Source does not exist: " << args.source << std::endl;
            return 1;
        }
        if (std::filesystem::is_regular_file(src)) {
            generate_file_code(args.source, args.dest, args.silent);
        } else if (std::filesystem::is_directory(src)) {
            generate_folder_code(args.source, args.dest, args.silent);
        } else {
            std::cerr << "Source is neither a file nor a directory: " << args.source << std::endl;
            return 1;
        }
    } catch (const std::exception& ex) {
        std::cerr << ex.what() << std::endl;
        return 1;
    }
    return 0;
} 