<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class UserGroupSeeder extends Seeder
{
    public function run(): void
    {
        $now = now();

        $groups = [
            [
                'name' => '普通用户',
                'code' => 'default',
                'description' => '默认用户组，新注册用户自动分配',
                'icon' => null,
                'color' => '#5FB878',
                'is_default' => 1,
                'sort' => 0,
                'status' => 1,
                'create_time' => $now,
                'update_time' => $now,
            ],
            [
                'name' => 'VIP用户',
                'code' => 'vip',
                'description' => 'VIP会员用户组',
                'icon' => null,
                'color' => '#FFB800',
                'is_default' => 0,
                'sort' => 1,
                'status' => 1,
                'create_time' => $now,
                'update_time' => $now,
            ],
        ];
        foreach ($groups as $group) {
            DB::table('user_groups')->updateOrInsert(
                ['code' => $group['code']],
                $group
            );
        }
    }
}
