<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('vendors', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->enum('type', ['msorg', 'smeplug']);
            $table->string('base_url')->nullable();
            $table->enum('auth_type', ['token', 'bearer']);
            $table->text('secret_encrypted');
            $table->enum('status', ['active', 'inactive'])->default('active');
            $table->unsignedInteger('timeout_seconds')->default(30);
            $table->boolean('webhook_enabled')->default(false);
            $table->timestamp('last_checked_at')->nullable();
            $table->unsignedInteger('last_latency_ms')->nullable();
            $table->timestamp('last_success_at')->nullable();
            $table->timestamps();

            $table->index(['type', 'status']);
        });

        Schema::create('networks', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('slug')->unique();
            $table->json('vendor_network_code_json')->nullable();
            $table->timestamps();
        });

        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('categories');
        Schema::dropIfExists('networks');
        Schema::dropIfExists('vendors');
    }
};

