<?php

use App\Models\Tenant;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

require __DIR__ . '/vendor/autoload.php';
$app = require_once __DIR__ . '/bootstrap/app.php';
$app->make(\Illuminate\Contracts\Console\Kernel::class)->bootstrap();

$tenantId = 'tenant1';
$tenant = Tenant::find($tenantId);

if (!$tenant) {
    echo "Tenant $tenantId not found.\n";
    exit(1);
}

tenancy()->initialize($tenant);

$columns = Schema::getColumnListing('core_config');
echo "Columns: " . implode(', ', $columns) . "\n";

// Update using only available columns
$data = ['value' => 'pt_BR'];
// If locale_code exists, set it? No, usually code key defines it.

$keys = [
    'general.general.locale.code',
    'app.locale'
];

foreach ($keys as $code) {
    DB::table('core_config')->updateOrInsert(
        ['code' => $code],
        $data
    );
    echo "Set $code to pt_BR\n";
}