<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

// Local mirror of the public hostseba.com knowledgebase. The drafter uses
// this alongside the markdown KB at docs/knowledge_base/*.md so customer
// replies cite the same articles a customer would find via the public KB
// index — same wording, same URLs.
//
// `source_id` is the WHMCS article id (the integer in the URL slug). The
// sync runner upserts on (source_id) so re-running is idempotent.
return new class extends Migration {
    public function up(): void
    {
        Schema::create('kb_articles', function (Blueprint $t) {
            $t->id();
            $t->unsignedInteger('source_id')->unique();
            $t->string('title', 255);
            $t->string('category', 128)->nullable()->index();
            $t->string('slug', 255)->nullable();
            $t->string('source_url', 500);
            $t->mediumText('body');             // plain-text body, scraped + stripped
            $t->mediumText('body_html')->nullable();   // raw HTML for debugging / display
            $t->boolean('enabled')->default(true)->index();
            $t->timestamp('last_synced_at')->nullable();
            $t->timestamps();
            $t->index('title');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('kb_articles');
    }
};
