<?php

namespace UltraguardPro\modules\uptime_monitor\schema;

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

use UltraguardPro\modules\core\AbstractModuleSchema;

class UptimeMonitorSchema extends AbstractModuleSchema {

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

    public function get_table_map(): array {
        return [
            'uptime_checks' => \UltraguardPro\modules\uptime_monitor\db\UptimeChecksTable::class,
            'ssl_checks'    => \UltraguardPro\modules\uptime_monitor\db\SslChecksTable::class,
        ];
    }

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

        return [
            $this->table( 'ultraguard_uptime_checks' ) =>
            "CREATE TABLE {$this->table('ultraguard_uptime_checks')} (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  check_url varchar(500) NOT NULL,
  status varchar(20) NOT NULL,
  response_code smallint(5) UNSIGNED DEFAULT NULL,
  response_time int(10) UNSIGNED DEFAULT NULL,
  error_message text DEFAULT NULL,
  check_source varchar(50) DEFAULT 'local',
  created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_status (status),
  KEY idx_created_at (created_at)
) {$cs};",
            $this->table( 'ultraguard_ssl_checks' ) =>
            "CREATE TABLE {$this->table('ultraguard_ssl_checks')} (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  domain varchar(255) NOT NULL,
  is_valid tinyint(1) DEFAULT 0,
  expiry_date datetime DEFAULT NULL,
  days_remaining int DEFAULT NULL,
  issuer varchar(255) DEFAULT NULL,
  subject varchar(255) DEFAULT NULL,
  fingerprint varchar(128) DEFAULT NULL,
  error_message text DEFAULT NULL,
  checked_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY idx_domain (domain(191)),
  KEY idx_expiry_date (expiry_date),
  KEY idx_checked_at (checked_at)
) {$cs};",
        ];
    }
}
