<?php

namespace Database\Seeders;

use App\Models\Barber;
use App\Models\Service;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

/**
 * Original synthetic demo data (Juan/Carlos barbers, three services).
 * Run manually: php artisan db:seed --class=DemoDatabaseSeeder
 */
class DemoDatabaseSeeder extends Seeder
{
    public function run(): void
    {
        User::create([
            'name' => 'Admin',
            'email' => 'admin@barbershop.com',
            'password' => Hash::make('password'),
            'role' => 'admin',
            'phone' => '1234567890',
            'is_active' => true,
        ]);

        $barber1 = User::create([
            'name' => 'Juan Pérez',
            'email' => 'juan@barbershop.com',
            'password' => Hash::make('password'),
            'role' => 'barber',
            'phone' => '1234567891',
            'is_active' => true,
        ]);

        $barber2 = User::create([
            'name' => 'Carlos García',
            'email' => 'carlos@barbershop.com',
            'password' => Hash::make('password'),
            'role' => 'barber',
            'phone' => '1234567892',
            'is_active' => true,
        ]);

        $weekdayMonFri = [];
        for ($w = 0; $w <= 6; $w++) {
            $weekdayMonFri[] = [
                'weekday' => $w,
                'enabled' => $w >= 1 && $w <= 5,
                'start' => '09:00',
                'end' => '17:00',
            ];
        }

        $barber1Record = Barber::create([
            'user_id' => $barber1->id,
            'bio' => 'Barbero profesional con 10 años de experiencia',
            'specialty' => 'Cortes modernos',
            'weekly_schedule' => $weekdayMonFri,
            'display_order' => 1,
        ]);

        $barber2Record = Barber::create([
            'user_id' => $barber2->id,
            'bio' => 'Especialista en cortes clásicos y barbas',
            'specialty' => 'Barba y cortes clásicos',
            'weekly_schedule' => $weekdayMonFri,
            'display_order' => 2,
        ]);

        $corte = Service::create([
            'name' => 'Corte',
            'category' => 'Corte',
            'description' => 'Corte de cabello tradicional',
            'duration_minutes' => 30,
            'price' => 8500,
            'is_active' => true,
        ]);

        $barba = Service::create([
            'name' => 'Barba',
            'category' => 'Barba',
            'description' => 'Arreglo de barba',
            'duration_minutes' => 20,
            'price' => 5500,
            'is_active' => true,
        ]);

        $combo = Service::create([
            'name' => 'Combo',
            'category' => 'Combo',
            'description' => 'Corte + Barba',
            'duration_minutes' => 45,
            'price' => 12000,
            'is_active' => true,
        ]);

        $barber1Record->services()->attach([$corte->id, $barba->id, $combo->id]);
        $barber2Record->services()->attach([$corte->id, $barba->id, $combo->id]);
    }
}
