<?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
    {
        // Statistik tayang per placement (RPD §12.2).
        Schema::create('ads_histories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('ad_id')->constrained('ads')->cascadeOnDelete(); // idads
            $table->foreignId('ads_placement_id')->constrained('ads_placements')->restrictOnDelete(); // idplacement
            $table->unsignedInteger('klik')->default(0);
            $table->date('tgl_update');
            $table->timestamps();

            $table->unique(['ad_id', 'ads_placement_id', 'tgl_update']);
        });
    }

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