<?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
    {
        if (!Schema::hasTable('supplier_applications')) {
            Schema::create('supplier_applications', function (Blueprint $table) {
                $table->id();
                $table->string('company_name', 150);
                $table->string('contact_name', 150);
                $table->string('email', 150);
                $table->string('phone', 50);
                $table->string('nif', 50)->nullable();
                $table->foreignId('province_id')->nullable()->constrained('provinces')->nullOnDelete();
                $table->string('supplier_type', 50)->default('producer');
                $table->string('product_category', 150)->nullable();
                $table->string('website', 200)->nullable();
                $table->text('company_description')->nullable();
                $table->text('products_description')->nullable();
                $table->string('supply_capacity', 150)->nullable();
                $table->text('message')->nullable();
                $table->string('attachment_path', 255)->nullable();
                $table->string('status', 30)->default('submitted');
                $table->text('notes')->nullable();
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('supplier_benefits')) {
            Schema::create('supplier_benefits', function (Blueprint $table) {
                $table->id();
                $table->string('title', 150);
                $table->text('description');
                $table->string('icon', 50)->default('heroicon-o-check-circle');
                $table->integer('sort_order')->default(0);
                $table->boolean('is_active')->default(true);
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('supplier_process_steps')) {
            Schema::create('supplier_process_steps', function (Blueprint $table) {
                $table->id();
                $table->integer('step_number')->default(1);
                $table->string('title', 150);
                $table->text('description');
                $table->string('icon', 50)->default('heroicon-o-document-text');
                $table->boolean('is_active')->default(true);
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('supplier_case_studies')) {
            Schema::create('supplier_case_studies', function (Blueprint $table) {
                $table->id();
                $table->string('supplier_name', 150);
                $table->string('category', 100);
                $table->string('title', 200);
                $table->text('excerpt')->nullable();
                $table->text('content')->nullable();
                $table->string('image_path', 255)->nullable();
                $table->string('metrics', 100)->nullable();
                $table->boolean('is_featured')->default(false);
                $table->boolean('is_active')->default(true);
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('supplier_faqs')) {
            Schema::create('supplier_faqs', function (Blueprint $table) {
                $table->id();
                $table->string('question', 255);
                $table->text('answer');
                $table->string('category', 100)->default('geral');
                $table->integer('sort_order')->default(0);
                $table->boolean('is_active')->default(true);
                $table->timestamps();
            });
        }
    }

    public function down(): void
    {
        Schema::dropIfExists('supplier_faqs');
        Schema::dropIfExists('supplier_case_studies');
        Schema::dropIfExists('supplier_process_steps');
        Schema::dropIfExists('supplier_benefits');
        Schema::dropIfExists('supplier_applications');
    }
};
