<?php
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/utils.php';
require_once __DIR__ . '/../config/config.php';

// Export all data types
$types = ['chores', 'groceries', 'meals', 'meal_plans', 'expenses', 'stores', 'grocery_lists', 'grocery_catalog', 'bank_transactions'];
$results = [];

foreach ($types as $type) {
    $data = readJsonFile($type . '.json');
    $filename = generateExportFilename($type);
    $exportPath = EXPORT_DESTINATION . '/' . $filename;
    
    if (file_put_contents($exportPath, json_encode($data, JSON_PRETTY_PRINT))) {
        $results[$type] = 'success';
    } else {
        $results[$type] = 'failed';
    }
}

// Log results
$logFile = EXPORT_DESTINATION . '/export_log.txt';
$timestamp = date('Y-m-d H:i:s');
$logMessage = "[$timestamp] Export results: " . json_encode($results) . "\n";
file_put_contents($logFile, $logMessage, FILE_APPEND); 