<?php

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('finance_accounts', function (Blueprint $table) {
            $table->string('id', 120)->primary();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('code', 60);
            $table->string('name');
            $table->string('type', 20);
            $table->string('parent_id', 120)->nullable();
            $table->boolean('is_active')->default(true);
            $table->timestamp('created_at_client')->nullable();
            $table->timestamp('updated_at_client')->nullable();
            $table->timestamps();

            $table->index(['user_id', 'code']);
        });
    }

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