<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\Core\Enums\StatusEnum;
use Modules\Inventory\Enums\CategoryTypeEnum;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('code')->nullable()->unique();
            $table->text('description')->nullable();
            $table->foreignId('inventory_department_id')->constrained()->cascadeOnDelete();
            $table->enum('category_type', CategoryTypeEnum::casesAsArray())->index()->default(CategoryTypeEnum::INVENTORY->value)->comment('inventory(stock + COGS), expense(direct expense), asset(fixed asset)');
            $table->boolean('has_stock')->default(true);
            $table->boolean('has_batch')->default(false);
            $table->boolean('has_expiry')->default(false);
            $table->foreignId('asset_account_id')->nullable()->constrained('chart_of_accounts')->restrictOnDelete();
            $table->foreignId('accum_dep_account_id')->nullable()->constrained('chart_of_accounts')->restrictOnDelete();
            $table->foreignId('dep_expense_account_id')->nullable()->constrained('chart_of_accounts')->restrictOnDelete();
            $table->enum('status', StatusEnum::casesAsArray())->index()->default(StatusEnum::ACTIVE);

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

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