<?php

namespace UltraguardPro\modules\reputation_monitor\schema;

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

use UltraguardPro\modules\core\AbstractModuleSchema;

class ReputationMonitorSchema extends AbstractModuleSchema {

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

    public function get_table_map(): array {
        return [
            'blacklist_checks'   => \UltraguardPro\modules\reputation_monitor\db\BlacklistChecksTable::class,
            'reputation_history' => \UltraguardPro\modules\reputation_monitor\db\ReputationHistoryTable::class,
        ];
    }

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

        return [
            $this->table( 'ultraguard_blacklist_checks' ) =>
            "CREATE TABLE {$this->table('ultraguard_blacklist_checks')} (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  source_id varchar(50) NOT NULL,
  source_name varchar(100) NOT NULL,
  check_type varchar(20) NOT NULL,
  target varchar(255) NOT NULL,
  status varchar(20) NOT NULL DEFAULT 'clean',
  threat_type varchar(100) DEFAULT NULL,
  details text DEFAULT NULL,
  last_checked_at datetime DEFAULT NULL,
  next_check_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),
  UNIQUE KEY idx_source_target (source_id, target(191)),
  KEY idx_status (status)
) {$cs};",
            $this->table( 'ultraguard_reputation_history' ) =>
            "CREATE TABLE {$this->table('ultraguard_reputation_history')} (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  source_id varchar(50) NOT NULL,
  target varchar(255) NOT NULL,
  old_status varchar(20) DEFAULT NULL,
  new_status varchar(20) NOT NULL,
  threat_type varchar(100) DEFAULT NULL,
  note text DEFAULT NULL,
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_source_id (source_id),
  KEY idx_created_at (created_at)
) {$cs};",
        ];
    }
}
