<?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('pedidos', function (Blueprint $table) {
            $table->id();
            // Datos del cliente
            $table->string('pedido',30)->nullable();
            $table->string('cuenta',20);
            $table->string('telefono',15);
            // Datos del auto
            $table->string('year',4);
            $table->string('marca',40);
            $table->string('modelo',40);
            $table->string('motor',20);
            // Datos envio del producto
            $table->string('folio_proveedor')->nullable();
            $table->string('numero_remision')->nullable();

            $table->boolean('is_venta_cerrada')->nullable();
            $table->unsignedBigInteger('venta_cerrada_user_id')->nullable();
            $table->foreign('venta_cerrada_user_id')->references('id')->on('users');

            $table->boolean('is_venta_entregada')->nullable();
            $table->unsignedBigInteger('venta_entregada_user_id')->nullable();
            $table->foreign('venta_entregada_user_id')->references('id')->on('users');



            $table->unsignedBigInteger('user_id');
            $table->foreign('user_id')->references('id')->on('users');

            $table->timestamp('venta_cerrada_at')->nullable();
            $table->timestamp('venta_entregada_at')->nullable();
            $table->timestamps();
        });
    }

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