<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('advertisements', function (Blueprint $table) {
            $table->id();
            $table->string('link');
            $table->string('customer_name', 150);
            $table->string('campaign_name', 150);
            $table->unsignedBigInteger('large_mobile_banner_id');
            $table->unsignedBigInteger('medium_rectangle_id');
            $table->unsignedBigInteger('large_leaderboard_id');
            $table->unsignedBigInteger('super_banner_id');
            $table->unsignedBigInteger('large_banner_id');
            $table->unsignedBigInteger('slider_banner_id');
            $table->date('expire_date')->nullable();
            $table->unsignedBigInteger('backend_user_id')->nullable();
            $table->timestamps();

            $table->foreign('large_mobile_banner_id')->references('id')
                ->on('media_items')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('medium_rectangle_id')->references('id')
                ->on('media_items')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('large_leaderboard_id')->references('id')
                ->on('media_items')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('super_banner_id')->references('id')
                ->on('media_items')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('large_banner_id')->references('id')
                ->on('media_items')->onDelete('CASCADE')->onUpdate('CASCADE');
            $table->foreign('slider_banner_id')->references('id')
                ->on('media_items')->onDelete('CASCADE')->onUpdate('CASCADE');

            $table->foreign('backend_user_id')->references('id')
                ->on('backend_users')->onDelete('SET NULL')->onUpdate('CASCADE');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('advertisements');
    }
};
