<?php
/**
 * DatabaseScannerSchema — DB schema for the Database Scanner module.
 *
 * Owns:
 *   • ultraguard_db_scan_results — per-row findings from database scans.
 *
 * @package UltraguardPro\modules\database_scanner\schema
 */

namespace UltraguardPro\modules\database_scanner\schema;

use UltraguardPro\modules\core\AbstractModuleSchema;

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

class DatabaseScannerSchema extends AbstractModuleSchema {

    public function get_module_id(): string { return 'database_scanner'; }

    public function get_table_map(): array {
        return [
            'db_scan_results' => \UltraguardPro\modules\database_scanner\db\DbScanResultsTable::class,
        ];
    }

    public function get_schemas(): array {
        $cs = $this->charset_collate();

        return [
            $this->table( 'ultraguard_db_scan_results' ) =>
            "CREATE TABLE {$this->table('ultraguard_db_scan_results')} (
  id               BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  scan_id          VARCHAR(36)  NOT NULL,
  db_table         VARCHAR(100) NOT NULL,
  column_name      VARCHAR(100) NOT NULL,
  row_id           BIGINT       NOT NULL,
  threat_type      VARCHAR(50)  NOT NULL,
  threat_level     ENUM('low','medium','high','critical') NOT NULL DEFAULT 'medium',
  matched_pattern  TEXT         DEFAULT NULL,
  content_excerpt  TEXT         DEFAULT NULL,
  status           ENUM('pending','cleaned','ignored','false_positive') NOT NULL DEFAULT 'pending',
  cleaned_at       DATETIME     DEFAULT NULL,
  created_at       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at       DATETIME     NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_scan_id      (scan_id),
  KEY idx_status       (status),
  KEY idx_threat_level (threat_level),
  KEY idx_status_created (status, created_at),
  KEY idx_created_at   (created_at)
) {$cs};",
        ];
    }
}
