<?php

namespace Lcmigrator\LcMigrator\StageInfo;

class StageInfo {
    private static int $totalSteps = 7;
    private static int $currentStep = 0;
    private static string $backupId;

    public static function initialize($id): string {
        self::$backupId = 'backup_'.$id;
        self::$currentStep = 0;
        return self::$backupId;
    }

    public static function updateProgress(string $backupId, int $step, int $total, string $message, string $status = 'running'): void {
        $progress = ($step / $total) * 100;
        $optionName = 'lc_migrator_backup_' . self::$backupId;
        
        update_option($optionName, array(
            'id' => $backupId,
            'progress' => $progress,
            'message' => $message,
            'step' => $step,
            'total' => $total,
            'status' => $status,
            'last_updated' => time()
        ), false);
    }
    public static function getProgressAsJson(string $backupId): array {
        $optionName = 'lc_migrator_backup_backup_' . $backupId;
        $progress = get_option($optionName);
        
        if (!$progress) {
            return [
                'success' => false,
                'message' => 'Backup progress not found'
            ];
        }

        return [
            'success' => true,
            'data' => $progress
        ];
    }
    public static function reset(string $backupId): void {
        // Reset static properties
        self::$currentStep = 0;
        self::$backupId = '';

        // Delete the backup option
        $optionName = 'lc_migrator_backup_backup_' . $backupId;
        delete_option($optionName);
    }
}