<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Niwa_AI_Admin_Autonomy_Executor {
    private $tools;

    public function __construct( $tools ) {
        $this->tools = $tools;
    }

    public function rollback_run( $run ) {
        $entries = isset( $run['rollback_entries'] ) && is_array( $run['rollback_entries'] ) ? $run['rollback_entries'] : array();
        if ( empty( $entries ) ) {
            return array(
                'success' => false,
                'error'   => 'Run nema rollback snapshot za vracanje.',
            );
        }

        $result = $this->tools->rollback_entries( $entries );
        if ( empty( $result['success'] ) ) {
            return $result;
        }

        return array(
            'success' => true,
            'summary' => sprintf( 'Rollback zavrsen. Vraceno %d snapshot zapisa.', count( $entries ) ),
        );
    }
}
