<?php

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

class AddAttachmentColumnsToWhatsappCampaignsTable extends Migration
{
    public function up()
    {
        Schema::table('whatsapp_campaigns', function (Blueprint $table) {
            if (!Schema::hasColumn('whatsapp_campaigns', 'attachment_path')) {
                $table->string('attachment_path')->nullable();
            }
            if (!Schema::hasColumn('whatsapp_campaigns', 'attachment_name')) {
                $table->string('attachment_name')->nullable();
            }
            if (!Schema::hasColumn('whatsapp_campaigns', 'attachment_mime')) {
                $table->string('attachment_mime')->nullable();
            }
            if (!Schema::hasColumn('whatsapp_campaigns', 'attachment_size')) {
                $table->integer('attachment_size')->nullable();
            }
        });
    }

    public function down()
    {
        // SQLite قد لا يدعم dropColumn بدون doctrine/dbal
        try {
            Schema::table('whatsapp_campaigns', function (Blueprint $table) {
                $table->dropColumn(['attachment_path','attachment_name','attachment_mime','attachment_size']);
            });
        } catch (\Exception $e) {}
    }
}
