<?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('settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique();
            $table->text('value')->nullable();
            $table->timestamps();
        });

        // Seed default settings
        DB::table('settings')->insert([
            ['key' => 'business_name', 'value' => 'Nama Usaha Anda', 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'business_address', 'value' => 'Alamat Usaha', 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'business_phone', 'value' => '', 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'signature_path', 'value' => null, 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'stamp_path', 'value' => null, 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'invoice_prefix', 'value' => 'INV', 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'receipt_prefix', 'value' => 'TTR', 'created_at' => now(), 'updated_at' => now()],
            ['key' => 'tax_rate', 'value' => '11', 'created_at' => now(), 'updated_at' => now()],
        ]);
    }

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