<?php

namespace UltraguardPro\modules\auto_updater\schema;

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

use UltraguardPro\modules\core\AbstractModuleSchema;

class AutoUpdaterSchema extends AbstractModuleSchema {

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

    public function get_table_map(): array {
        return [
            'update_log' => \UltraguardPro\modules\auto_updater\db\UpdateLogTable::class,
        ];
    }

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

        return [
            $this->table( 'ultraguard_update_log' ) =>
            "CREATE TABLE {$this->table('ultraguard_update_log')} (
  id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  component_type varchar(20) NOT NULL,
  component_slug varchar(255) NOT NULL,
  component_name varchar(255) NOT NULL,
  old_version varchar(50) NOT NULL,
  new_version varchar(50) NOT NULL,
  status varchar(20) NOT NULL DEFAULT 'pending',
  trigger_type varchar(20) DEFAULT 'auto',
  error_message text DEFAULT NULL,
  snapshot_path text DEFAULT NULL,
  rolled_back_at datetime DEFAULT NULL,
  updated_by bigint(20) UNSIGNED 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_component_type (component_type),
  KEY idx_status (status),
  KEY idx_created_at (created_at)
) {$cs};",
        ];
    }
}
