<?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
    {
        Schema::create('confeccions', function (Blueprint $table) {
            $table->id();

            // Relaciones
            $table->foreignId('proveedor_id')
                ->constrained('proveedors')
                ->cascadeOnDelete();

            $table->foreignId('orden_produccion_id')
                ->constrained('orden_produccions')
                ->cascadeOnDelete();

            // Envío
            $table->date('fecha_envio');
            $table->integer('cantidad_enviada');

            // Recepción
            $table->date('fecha_recepcion')->nullable();
            $table->integer('cantidad_recibida')->nullable();
            $table->integer('prendas_defectuosas')->default(0);

            // Costos
            $table->decimal('valor_por_prenda', 12, 2);
            $table->decimal('total_pagar', 14, 2)->default(0);

            // Estado
            $table->enum('estado', ['pendiente', 'parcial', 'completo'])
                ->default('pendiente');

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

    public function down(): void
    {
        Schema::dropIfExists('confeccions');
    }
};
