<?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('precios_por_bien', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('bien_id');
            $table->decimal('precio', 12, 2);
            $table->decimal('porcentaje_utilidad', 5, 2)->default(0);
            $table->date('fecha_registro');
            $table->string('cedula_usuario', 20)->nullable();

            $table->index('fecha_registro');
            $table->index('cedula_usuario');

            $table->foreign('bien_id')->references('id')->on('bienes')->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('cedula_usuario')->references('cedula')->on('users')->onUpdate('cascade');
        });
    }

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