<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('units', function (Blueprint $table) {
            $table->id();
            $table->string('name'); // e.g., Pieces, Kilograms
            $table->string('code')->unique(); // e.g., pcs, kg
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        // Seed default units
        DB::table('units')->insert([
            ['name' => 'Pieces', 'code' => 'pcs', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Kilograms', 'code' => 'kg', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Tons', 'code' => 'tons', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Liters', 'code' => 'ltr', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Boxes', 'code' => 'box', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Dozens', 'code' => 'doz', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Sets', 'code' => 'set', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Meters', 'code' => 'mtr', 'created_at' => now(), 'updated_at' => now()],
        ]);
    }

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