<?php

use App\Enums\EntityStatus;
use App\Enums\PaymentMethod;
use App\Enums\PropertyType;
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->string('title')->nullable();
            $table->string('code');
            $table->longText('location')->nullable();
            $table->string('latitud')->nullable();
            $table->string('longitud')->nullable();
            $table->float('surface',15,2)->nullable();
            $table->longText('description')->nullable();
            $table->dateTime('delivery_date')->nullable();
            $table->enum('status', ['AVAILABLE', 'SALE', 'PRESALE', 'DELIVERED'])->default('AVAILABLE');
            $table->float('precio_por_m2')->nullable();
            $table->enum('property_type',[
                PropertyType::HOUSE->name,
                PropertyType::DEPARTAMENT->name,
                PropertyType::LAND->name,
                PropertyType::OFFICE->name,
                PropertyType::PARK->name ]);

            $table->float('base_price')->nullable();
            $table->float('percentage_initial_fee',5,2)->nullable();
            $table->float('initial_fee',15,2)->nullable();
            $table->float('final_price')->nullable();
            // $table->enum('payment_method', [PaymentMethod::DIRECTCREDIT->value, PaymentMethod::CASH->value, PaymentMethod::BANKCREDIT->value])->nullable();

            $table->unsignedBigInteger('property_type_id');
            $table->foreign('property_type_id')->references('id')->on('type_properties');

            $table->unsignedBigInteger('project_id');
            $table->foreign('project_id')->references('id')->on('projects');

            $table->enum('entity_status',[EntityStatus::ACTIVE->value, EntityStatus::INACTIVE->value])->default(EntityStatus::ACTIVE->value);

            $table->timestamps();
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->unsignedBigInteger('deleted_by')->nullable();
            $table->foreign('created_by')->references('id')->on('users');
            $table->foreign('updated_by')->references('id')->on('users');
            $table->foreign('deleted_by')->references('id')->on('users');

            $table->softDeletes();
        });
    }

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