<?php

namespace Database\Seeders;

use App\Actions\Teams\CreateTeam;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class AdminUserSeeder extends Seeder
{
    /**
     * Seed the application's admin user.
     *
     * Credentials are configurable via ADMIN_DEFAULT_EMAIL / ADMIN_DEFAULT_PASSWORD
     * (see config/admin.php); the defaults below are local-dev only.
     */
    public function run(CreateTeam $createTeam): void
    {
        $user = User::query()->firstOrCreate(
            ['email' => config('admin.default_email')],
            [
                'name' => 'Admin',
                'password' => Hash::make(config('admin.default_password')),
                'email_verified_at' => now(),
                'is_admin' => true,
            ]
        );

        if ($user->wasRecentlyCreated) {
            $createTeam->handle($user, $user->name."'s Team", isPersonal: true);
        }
    }
}
