<?php

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

return new class extends Migration {
    public function up()
    {
        Schema::create('photos', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id'); // User yang upload
            $table->unsignedBigInteger('customer_id'); // Customer yang mendapatkan foto
            $table->unsignedBigInteger('booking_id')->nullable(); // Tambahkan booking_id (nullable)
            $table->string('file_path'); // Path file
            $table->string('token', 10)->index(); // Token akses
            $table->timestamps();

            // Foreign Keys
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('customer_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('booking_id')->references('id')->on('bookings')->onDelete('cascade'); // Relasi ke bookings
        });
    }

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