<?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
    {
        Schema::create('properties', function (Blueprint $table) {
            $table->id();
            $table->foreignId('landlord_id')->constrained('users')->onDelete('cascade');
            $table->tinyInteger('property_type')->comment('1=house, 2=apartment, 3=room, 4=hostel, 5=office');
            $table->string('title');
            $table->text('description')->nullable();
            $table->decimal('monthly_rent', 10, 2);
            $table->decimal('deposit_amount', 10, 2);
            $table->string('address');
            $table->decimal('latitude', 10, 8)->nullable();
            $table->decimal('longitude', 11, 8)->nullable();
            $table->integer('bedrooms')->nullable();
            $table->integer('bathrooms')->nullable();
            $table->integer('size_sqm')->nullable();
            $table->boolean('is_furnished')->default(false);
            $table->tinyInteger('status')->default(3)->comment('1=available, 2=occupied, 3=pending, 4=maintenance');
            $table->boolean('is_verified')->default(false);
            $table->timestamps();
            
            // Indexes for better performance
            $table->index(['landlord_id', 'status']);
            $table->index(['property_type', 'status']);
            $table->index(['latitude', 'longitude']);
        });
    }

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