<?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('leads', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable();
            $table->string('email')->index();
            $table->string('phone')->nullable();
            $table->string('source');                 // assessment:financial-health | tool:debt-payoff | newsletter
            $table->string('segment')->nullable();    // individual | corporate | diaspora
            $table->json('meta')->nullable();
            $table->boolean('consented')->default(true);
            $table->timestamps();
        });

        Schema::create('tool_results', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->string('tool');                   // debt-payoff | compound-growth | emergency-fund
            $table->string('label')->nullable();      // user-given name, e.g. "My 2026 plan"
            $table->json('inputs');
            $table->json('outputs')->nullable();
            $table->timestamps();
        });

        Schema::create('inquiries', function (Blueprint $table) {
            $table->id();
            $table->string('type');                   // corporate | speaking | coaching | partnership | media | support
            $table->string('name');
            $table->string('email');
            $table->string('phone')->nullable();
            $table->string('organization')->nullable();
            $table->text('message');
            $table->string('status')->default('new'); // new | in_progress | closed
            $table->timestamps();
        });

        Schema::create('testimonials', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('role')->nullable();
            $table->text('quote');
            $table->string('context')->nullable();    // course | coaching | book
            $table->boolean('is_featured')->default(false);
            $table->unsignedSmallInteger('sort')->default(0);
            $table->timestamps();
        });

        Schema::create('posts', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('slug')->unique();
            $table->string('category')->nullable();
            $table->text('excerpt')->nullable();
            $table->longText('body');
            $table->string('cover_path')->nullable();
            $table->timestamp('published_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('posts');
        Schema::dropIfExists('testimonials');
        Schema::dropIfExists('inquiries');
        Schema::dropIfExists('tool_results');
        Schema::dropIfExists('leads');
    }
};
