<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Field jenis iklan + platform + negara + verifikasi pada campaign.
     */
    public function up(): void
    {
        Schema::table('ads', function (Blueprint $table) {
            $table->enum('ad_type', ['affiliate', 'link_website', 'backlink', 'press_release'])->default('affiliate')->after('url');
            $table->foreignId('ad_platform_id')->nullable()->constrained('ad_platforms')->nullOnDelete()->after('ad_type');
            $table->string('target_country', 5)->nullable()->after('ad_platform_id');
            $table->string('verification_code', 40)->nullable()->unique()->after('target_country');
            $table->timestamp('verified_at')->nullable()->after('verification_code');
        });
    }

    public function down(): void
    {
        Schema::table('ads', function (Blueprint $table) {
            $table->dropForeign(['ad_platform_id']);
            $table->dropColumn(['ad_type', 'ad_platform_id', 'target_country', 'verification_code', 'verified_at']);
        });
    }
};
