<?php
/**
 * تکمیل SRD v18.0 — مهر شرکت، بازبینی ارشد، اعلان
 * php run-service-srd-complete.php
 */
declare(strict_types=1);

if ( ! defined( 'ACC_BASE_PATH' ) ) {
    define( 'ACC_BASE_PATH', __DIR__ );
    require __DIR__ . '/standalone/bootstrap.php';
}

header( 'Content-Type: application/json; charset=utf-8' );
global $wpdb;
$pre = $wpdb->prefix;

$cols = [
    [ 'svc_reports', 'company_stamp', 'TEXT NULL' ],
    [ 'svc_reports', 'senior_review_status', "VARCHAR(20) NOT NULL DEFAULT 'none'" ],
    [ 'svc_reports', 'senior_review_note', 'TEXT NULL' ],
    [ 'svc_reports', 'senior_reviewed_by', 'BIGINT UNSIGNED NULL' ],
    [ 'svc_reports', 'senior_reviewed_at', 'DATETIME NULL' ],
    [ 'svc_reports', 'notified_at', 'DATETIME NULL' ],
];

$added = [];
foreach ( $cols as [ $tbl, $col, $def ] ) {
    $full = $pre . $tbl;
    if ( ! $wpdb->get_var( "SHOW COLUMNS FROM {$full} LIKE '{$col}'" ) ) {
        $wpdb->query( "ALTER TABLE {$full} ADD COLUMN {$col} {$def}" );
        $added[] = "{$tbl}.{$col}";
    }
}

update_option( 'acc_engine_db_version', '18.0' );

echo json_encode( [
    'success'    => true,
    'db_version' => '18.0',
    'columns_added' => $added,
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT );
