<?php

namespace Database\Seeders;

use App\Models\Service;
use App\Models\ServiceCategory;
use Illuminate\Database\Seeder;

class ServiceSeeder extends Seeder
{
    public function run(): void
    {
        $categories = ServiceCategory::all();
        if ($categories->isEmpty()) {
            return;
        }

        $hair = $categories->firstWhere('code', 'HAIR');
        $skin = $categories->firstWhere('code', 'SKIN');
        $nails = $categories->firstWhere('code', 'NAILS');
        $spa = $categories->firstWhere('code', 'SPA');

        $services = [
            ['category' => $hair, 'name' => 'Haircut', 'duration' => 30, 'buffer' => 5, 'price' => 25.00, 'code' => 'SRV001'],
            ['category' => $hair, 'name' => 'Hair Color', 'duration' => 90, 'buffer' => 10, 'price' => 85.00, 'code' => 'SRV002'],
            ['category' => $hair, 'name' => 'Blow Dry', 'duration' => 45, 'buffer' => 5, 'price' => 35.00, 'code' => 'SRV003'],
            ['category' => $hair, 'name' => 'Hair Treatment', 'duration' => 45, 'buffer' => 5, 'price' => 50.00, 'code' => 'SRV009'],
            ['category' => $skin, 'name' => 'Basic Facial', 'duration' => 60, 'buffer' => 10, 'price' => 55.00, 'code' => 'SRV004'],
            ['category' => $skin, 'name' => 'Deep Cleanup', 'duration' => 45, 'buffer' => 5, 'price' => 40.00, 'code' => 'SRV005'],
            ['category' => $skin, 'name' => 'Anti-Aging Facial', 'duration' => 75, 'buffer' => 10, 'price' => 95.00, 'code' => 'SRV010'],
            ['category' => $nails, 'name' => 'Manicure', 'duration' => 45, 'buffer' => 5, 'price' => 30.00, 'code' => 'SRV006'],
            ['category' => $nails, 'name' => 'Pedicure', 'duration' => 60, 'buffer' => 5, 'price' => 45.00, 'code' => 'SRV007'],
            ['category' => $nails, 'name' => 'Gel Nails', 'duration' => 60, 'buffer' => 5, 'price' => 55.00, 'code' => 'SRV011'],
            ['category' => $spa, 'name' => 'Swedish Massage', 'duration' => 60, 'buffer' => 10, 'price' => 75.00, 'code' => 'SRV008'],
            ['category' => $spa, 'name' => 'Deep Tissue Massage', 'duration' => 90, 'buffer' => 10, 'price' => 110.00, 'code' => 'SRV012'],
        ];

        foreach ($services as $i => $s) {
            Service::firstOrCreate(
                ['service_code' => $s['code']],
                [
                    'category_id' => $s['category']->id,
                    'branch_id' => null,
                    'name' => $s['name'],
                    'duration_minutes' => $s['duration'],
                    'buffer_minutes' => $s['buffer'],
                    'price' => $s['price'],
                    'gender_applicability' => 'unisex',
                    'online_booking_enabled' => true,
                    'status' => 'active',
                    'sort_order' => $i + 1,
                ]
            );
        }
    }
}
