<?php

namespace Database\Seeders;

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

/**
 * Production rescue: ensures admin@barbershop.com exists and password is "password"
 * without touching clients or appointments. Run: php artisan db:seed --class=ResetAdminPasswordSeeder
 */
class ResetAdminPasswordSeeder extends Seeder
{
    public function run(): void
    {
        $now = now();
        $row = DB::table('users')->where('email', 'admin@barbershop.com')->first();

        if ($row) {
            DB::table('users')->where('id', $row->id)->update([
                'password' => Hash::make('password'),
                'role' => 'admin',
                'is_active' => true,
                'updated_at' => $now,
            ]);
        } else {
            DB::table('users')->insert([
                'name' => 'Admin',
                'email' => 'admin@barbershop.com',
                'password' => Hash::make('password'),
                'role' => 'admin',
                'phone' => null,
                'is_active' => true,
                'created_at' => $now,
                'updated_at' => $now,
            ]);
        }
    }
}
