<?php

use ZenoChatbot\Framework\Database\Migration\Migration;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

return new class extends Migration {
    protected $table = 'zenochatbot_saved_replies';

    public function up()
    {
        return $this->create($this->table, [
            'id' => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
            'question' => 'TEXT NOT NULL',
            'answer' => 'LONGTEXT NOT NULL',
            'match_type' => "VARCHAR(20) NOT NULL DEFAULT 'exact'",
            'keywords' => 'TEXT NULL',
            'language' => "VARCHAR(10) NOT NULL DEFAULT 'en'",
            'priority' => 'INT NOT NULL DEFAULT 0',
            'hit_count' => 'INT NOT NULL DEFAULT 0',
            'embedding' => 'LONGTEXT NULL',
            'embedding_provider' => "VARCHAR(50) NULL",
            'is_active' => 'TINYINT(1) NOT NULL DEFAULT 1',
            'created_at' => 'DATETIME NOT NULL',
            'updated_at'         => 'DATETIME NOT NULL',
        ], [
            'INDEX idx_active_priority (is_active, priority)',
            'INDEX idx_match_type (match_type)',
            'INDEX idx_language (language)'
        ]);
    }

    public function down()
    {
        return $this->drop($this->table);
    }
};

