<?php

use App\Database\Blueprint;
use App\Enums\DbStatusFieldEnum;
use App\Enums\ProductTypeEnum;
use App\Enums\ProductUnitEnum;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('products', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable();
            $table->integer('supplier_id')->nullable(); // beszallito azonosito
            $table->integer('producer_id')->nullable(); // gyártó azonositója
            $table->integer('packing')->nullable(); // kiszerelés szamadat
            $table->integer('unitValue')->nullable(); // suly/urtalamom ertek
            $table->enum('productUnit', ProductUnitEnum::getKeys())->nullable(); // mértékegység
            $table->enum('sellerUnit', ProductUnitEnum::getKeys())->nullable(); // Eladasi egyseg
            $table->double('unitMultiplier')->nullable(); // Egységszozó
            $table->enum('amountUnit', ProductUnitEnum::getKeys())->nullable(); // mennyisegi egyseg
            $table->double('vat')->nullable(); // áfa
            $table->string('supplierProductNumber')->nullable(); // beszallito cikkszam

            $table->integer('product_group_id')->nullable(); // termék csoport
            $table->string('hooreycaId')->nullable(); // hooreyca azonosito
            $table->string('buyerProductName')->nullable(); // vevői terméknev
            $table->string('buyerProductNumber')->nullable(); // vevői cikkszám

            $table->text('note')->nullable(); // megjegyezes
            $table->enum('type', ProductTypeEnum::getKeys())->nullable();
            $table->enum('status', DbStatusFieldEnum::getValues())->default(DbStatusFieldEnum::draft);
            $table->boolean('canSee')->default(true);

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

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