<?php

namespace Database\Seeders;

use App\Models\Business;
use App\Models\Category;
use App\Models\City;
use Illuminate\Database\Seeder;

class BusinessSeeder extends Seeder
{
    public function run(): void
    {
        $samples = [
            ['name' => 'Hodan Halal Grocery', 'category' => 'Halal grocery', 'city' => 'Minneapolis', 'description' => 'Family-run halal grocery stocking East African staples, fresh meat and spices.', 'phone' => '+1 612 555 0142', 'website' => 'https://example.com', 'featured' => true],
            ['name' => 'Dahabshiil Remittance', 'category' => 'Remittance/hawala', 'city' => 'London', 'description' => 'Fast, reliable money transfers to Somalia and East Africa.', 'phone' => '+44 20 7946 0958', 'website' => 'https://example.com', 'featured' => true],
            ['name' => 'Baraka Restaurant', 'category' => 'Restaurant', 'city' => 'Melbourne', 'description' => 'Authentic Somali cuisine, sambusa and camel meat specialities.', 'phone' => '+61 3 9000 1234', 'website' => null, 'featured' => false],
            ['name' => 'Iftin Legal Aid Centre', 'category' => 'Legal aid', 'city' => 'Toronto', 'description' => 'Free immigration and family law advice for the Somali community.', 'phone' => '+1 416 555 0199', 'website' => null, 'featured' => false],
            ['name' => 'Nuur Driving School', 'category' => 'Driving school', 'city' => 'Columbus', 'description' => 'Patient instructors offering lessons in English and Somali.', 'phone' => '+1 614 555 0123', 'website' => null, 'featured' => false],
            ['name' => 'Masjid Al-Noor', 'category' => 'Mosque', 'city' => 'Seattle', 'description' => 'Community mosque with daily prayers, Quran classes and weekend madrasa.', 'phone' => null, 'website' => null, 'featured' => true],
        ];

        foreach ($samples as $sample) {
            $category = Category::where('name', $sample['category'])->first();
            $city = City::where('name', $sample['city'])->first();

            if (! $category || ! $city) {
                continue;
            }

            Business::firstOrCreate(
                ['name' => $sample['name']],
                [
                    'category_id' => $category->id,
                    'city_id' => $city->id,
                    'description' => $sample['description'],
                    'phone' => $sample['phone'],
                    'website' => $sample['website'],
                    'status' => 'approved',
                    'featured' => $sample['featured'],
                ]
            );
        }
    }
}
