<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Contact;
use App\Models\Hotel;
use Illuminate\Support\Facades\DB;

class ContactSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $hotels = Hotel::all();

        if ($hotels->isEmpty()) {
            return;
        }

        foreach ($hotels as $hotel) {
            $this->seedContactsForHotel($hotel->id);
        }
    }

    private function seedContactsForHotel($hotelId)
    {
        $contacts = [
            [
                'hotel_id' => $hotelId,
                'first_name' => 'John',
                'last_name' => 'Doe',
                'company_name' => 'Corporate Guest Inc',
                'email' => 'john.doe@corporate.com',
                'phone' => '+256 700 123456',
                'contact_type' => 'customer',
                'category' => 'Corporate',
                'tax_number' => 'TIN12345678',
                'country' => 'Uganda',
                'city' => 'Kampala',
                'address' => 'Plot 1, Corporate Way',
                'status' => 'active'
            ],
            [
                'hotel_id' => $hotelId,
                'first_name' => 'Alice',
                'last_name' => 'Smith',
                'company_name' => 'Travelers Co',
                'email' => 'alice@travelers.com',
                'phone' => '+256 750 987654',
                'contact_type' => 'vendor',
                'category' => 'Travel Agent',
                'status' => 'active'
            ],
            [
                'hotel_id' => $hotelId,
                'first_name' => 'Supplier',
                'last_name' => 'One',
                'company_name' => 'Fresh Foods Ltd',
                'email' => 'info@freshfoods.co.ug',
                'phone' => '+256 772 000000',
                'contact_type' => 'vendor',
                'category' => 'F&B Supplier',
                'status' => 'active'
            ],
            [
                'hotel_id' => $hotelId,
                'first_name' => 'Bulk',
                'last_name' => 'Supplies',
                'company_name' => 'Hotel General Supplies',
                'email' => 'sales@hotelsupplies.com',
                'phone' => '+256 782 111111',
                'contact_type' => 'vendor',
                'category' => 'General',
                'status' => 'active'
            ],
        ];

        foreach ($contacts as $contact) {
            Contact::create($contact);
        }
    }
}
