<?php

use App\Models\ConfigGroup;
use App\Models\ConfigItem;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
    public function up(): void
    {
        $basicGroupId = ConfigGroup::where('code', 'basic')->value('id');
        if (!$basicGroupId) {
            return;
        }

        ConfigItem::updateOrCreate(
            ['code' => 'site_analytics'],
            [
                'group_id' => $basicGroupId,
                'name' => '统计代码',
                'value' => '',
                'type' => 'textarea',
                'options' => null,
                'tips' => '第三方统计代码（如百度统计、Google Analytics等），将自动嵌入前台页面',
                'sort' => 7,
                'status' => 1,
            ]
        );
    }

    public function down(): void
    {
        ConfigItem::where('code', 'site_analytics')->delete();
    }
};
