<?php

namespace UltraguardPro\modules\traffic_monitor\schema;

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

use UltraguardPro\modules\core\AbstractModuleSchema;

class TrafficMonitorSchema extends AbstractModuleSchema {

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

    public function get_table_map(): array {
        return [
            'traffic_logs' => \UltraguardPro\modules\traffic_monitor\db\TrafficLogsTable::class,
        ];
    }

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

        return [
            $this->table( 'ultraguard_traffic_logs' ) =>
            "CREATE TABLE {$this->table('ultraguard_traffic_logs')} (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  ip_address varchar(45) NOT NULL,
  ip_country varchar(2) DEFAULT NULL,
  ip_country_name varchar(60) DEFAULT NULL,
  ip_city varchar(100) DEFAULT NULL,
  user_agent text DEFAULT NULL,
  request_method varchar(10) DEFAULT NULL,
  request_uri text NOT NULL,
  request_host varchar(255) DEFAULT NULL,
  referrer text DEFAULT NULL,
  response_code smallint(5) UNSIGNED DEFAULT NULL,
  user_id bigint(20) UNSIGNED DEFAULT NULL,
  threat_type varchar(50) DEFAULT NULL,
  threat_level varchar(20) NOT NULL DEFAULT 'none',
  was_blocked tinyint(1) NOT NULL DEFAULT 0,
  block_reason varchar(100) DEFAULT NULL,
  is_bot tinyint(1) NOT NULL DEFAULT 0,
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_ip_address (ip_address),
  KEY idx_threat_type (threat_type),
  KEY idx_was_blocked (was_blocked),
  KEY idx_created_at (created_at),
  KEY idx_user_id (user_id)
) {$cs};",
        ];
    }
}
