<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Customer;
use App\Models\User;

class CustomerSeeder extends Seeder
{
    public function run(): void
    {
        // Get the first user (or create one if needed)
        $user = User::first();

        if (!$user) {
            return; // No user exists, skip seeding
        }

        // Create sample customers
        $customers = [
            [
                'name' => 'Acme Corporation',
                'email' => 'contact@acme.com',
                'phone' => '555-0101',
                'address' => '123 Business St, City, State 12345',
                'user_id' => $user->id,
            ],
            [
                'name' => 'Global Industries',
                'email' => 'info@global-ind.com',
                'phone' => '555-0102',
                'address' => '456 Industrial Ave, City, State 12345',
                'user_id' => $user->id,
            ],
            [
                'name' => 'Tech Solutions Ltd',
                'email' => 'sales@techsol.com',
                'phone' => '555-0103',
                'address' => '789 Tech Park, City, State 12345',
                'user_id' => $user->id,
            ],
            [
                'name' => 'Local Services Inc',
                'email' => 'hello@localservices.com',
                'phone' => '555-0104',
                'address' => '321 Main St, City, State 12345',
                'user_id' => $user->id,
            ],
        ];

        foreach ($customers as $customer) {
            Customer::firstOrCreate(
                ['email' => $customer['email']],
                $customer
            );
        }
    }
}
