<?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('products', function (Blueprint $table) {
            $table->id();
            $table->string('code')->unique()->comment('商品編號');
            $table->string('name')->comment('商品名稱');
            $table->foreignId('category_id')->constrained('categories')->onDelete('restrict')->comment('商品分類');
            $table->string('brand')->nullable()->comment('品牌');
            $table->text('specification')->nullable()->comment('規格描述');
            
            // Unit conversion
            $table->string('base_unit')->comment('基本庫存單位 (e.g. g, ml)');
            $table->string('large_unit')->nullable()->comment('大單位 (e.g. 桶, 箱)');
            $table->decimal('conversion_rate', 10, 4)->default(1)->comment('換算率 (1 大單位 = ? 基本單位)');
            $table->string('purchase_unit')->nullable()->comment('採購單位');

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

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