<?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('invoice_billings', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique(); // gib, logo, parasut, vb.
            $table->string('display_name'); // GİB E-Fatura, Logo E-Fatura, Paraşüt E-Fatura
            $table->enum('type', ['e-invoice', 'e-archive'])->default('e-invoice');
            $table->boolean('is_active')->default(true);
            $table->boolean('is_automatic')->default(false);
            $table->json('settings')->nullable(); // Modül ayarları
            $table->json('mapping_fields')->nullable(); // Eşleştirme alanları
            $table->enum('status', ['active', 'inactive', 'error'])->default('active');
            $table->text('last_error')->nullable();
            $table->timestamp('last_sync_at')->nullable();
            $table->timestamps();

            $table->index(['is_active', 'is_automatic']);
            $table->index(['type', 'status']);
        });
    }

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