<?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
    {
        // 1. Membuat tabel transactions
        Schema::create('transactions', function (Blueprint $table) {
            $table->id();
            $table->string('booking_code')->unique();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('room_id')->constrained()->cascadeOnDelete();

            $table->date('survey_date');
            $table->integer('booking_fee')->default(10000); // Biaya komitmen Rp 10.000

            $table->string('payment_method');
            // Status Pembayaran: pending, paid, refunded, expired
            $table->string('payment_status')->default('pending');
            // Status Survei: menunggu, deal, batal_user, batal_owner
            $table->string('survey_status')->default('menunggu');

            // Batas waktu pembayaran (1 jam dari waktu dibuat)
            $table->timestamp('payment_expired_at')->nullable();
            $table->timestamps();
        });

        // 2. Menambahkan kolom sanksi di tabel boarding_houses yang sudah ada
        Schema::table('boarding_houses', function (Blueprint $table) {
            $table->boolean('is_suspended')->default(false)->after('name');
            $table->integer('penalty_fee')->default(0)->after('is_suspended');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('transactions');
        Schema::table('boarding_houses', function (Blueprint $table) {
            $table->dropColumn(['is_suspended', 'penalty_fee']);
        });
    }
};
