<?php

declare(strict_types=1);

namespace KimaAI\Database;

use KimaAI\Models\ChatCsatModel;
use KimaAI\Models\ChatFeedbackAdminModel;
use KimaAI\Models\ChatFeedbackModel;
use KimaAI\Models\ChatModel;
use KimaAI\Models\EmbeddingLogsModel;
use KimaAI\Models\EmbeddingsModel;
use KimaAI\Models\ImageModel;
use KimaAI\Models\LinkSuggestionModel;

defined('ABSPATH') || exit;

final class SchemaRegistry {

  /**
   * Return all schema model classes (each uses HasSchema::createTableSql()).
   *
   * @return array<class-string>
   */
  public static function models(): array {
    return [
      ChatModel::class,
      ChatFeedbackModel::class,
      ChatCsatModel::class,
      ChatFeedbackAdminModel::class,
      ImageModel::class,
      EmbeddingsModel::class,
      EmbeddingLogsModel::class,
      LinkSuggestionModel::class,
    ];
  }

  /**
   * Applies all registered database schemas.
   */
  public static function applySchema(): void {
    $wpdb = Db::wpdb();

    require_once ABSPATH . 'wp-admin/includes/upgrade.php';

    foreach (self::models() as $model) {
      dbDelta($model::createTableSql($wpdb));
    }
  }
}
