<?php

use App\Enums\ProductStockQuality;
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('stok_opname_items', function (Blueprint $table): void {
            $table->id();

            $table->foreignId('stok_opname_id')->constrained('stok_opnames')->cascadeOnDelete();
            $table->foreignId('product_variant_id')->constrained('product_variants')->cascadeOnDelete();
            $table->enum('stock_quality', ProductStockQuality::values())->default(ProductStockQuality::GOOD->value);

            $table->unsignedInteger('system_stock')->default(0);
            $table->unsignedInteger('physical_stock')->default(0);
            $table->integer('difference')->default(0);
            $table->text('notes')->nullable();

            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
        });
    }

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