<?php

declare(strict_types=1);

use Hypervel\Database\Migrations\Migration;
use Hypervel\Support\Facades\Schema;
use Hypervel\Support\Str;

class AddDefaultOrgTypeSystemSetting extends Migration
{
    public function up(): void
    {
        $exists = \DB::table('system_settings')->where('key', 'default_org_type')->exists();
        if (!$exists) {
            \DB::table('system_settings')->insert([
                'hashkey'     => (string) Str::uuid() . Str::random(100),
                'key'         => 'default_org_type',
                'value'       => 'COOPERATIVE',
                'type'        => 'select',
                'options'     => json_encode(['COOPERATIVE', 'NGO', 'CORPORATION']),
                'group'       => 'general',
                'label'       => 'Default Organization Type',
                'description' => 'Pre-selected type when creating a new organization. Options: Cooperative, NGO, Corporation/Company.',
                'created_at'  => now(),
                'updated_at'  => now(),
            ]);
        }
    }

    public function down(): void
    {
        \DB::table('system_settings')->where('key', 'default_org_type')->delete();
    }
}
