<?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
    {
        Schema::create('boosts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('listing_id')->constrained()->onDelete('cascade');
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->string('city', 100);
            $table->decimal('bid_amount', 10, 2); // ₹ per day
            $table->enum('status', ['active', 'paused', 'exhausted'])->default('active');
            $table->timestamp('last_deducted_at')->nullable();
            $table->timestamp('started_at')->useCurrent();
            $table->timestamp('ends_at')->nullable();
            $table->timestamps();

            // One active boost per listing per city
            $table->unique(['listing_id', 'city']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('boosts');
    }
};
