<?php

namespace Database\Seeders;

use App\Models\City;
use App\Models\Continent;
use App\Models\Country;
use App\Models\Lead;
use App\Models\Tradefair;
use Illuminate\Database\Seeder;

class LeadVendorSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $continent = Continent::firstOrCreate(
            ['code' => 'AS'],
            ['name' => 'Asia', 'status' => 1]
        );

        $country = Country::firstOrCreate(
            ['continent' => $continent->name, 'name' => 'UAE'],
            ['status' => true]
        );

        $city = City::firstOrCreate(
            ['country_id' => $country->id, 'name' => 'Dubai'],
            ['status' => true]
        );

        $tradefair = Tradefair::updateOrCreate(
            ['fair_name' => 'Dubai Build Expo 2026'],
            [
                'contient' => $continent->name,
                'country' => $country->name,
                'eventvenue' => $city->name,
                'event_start_date' => now()->addDays(30)->toDateString(),
                'event_end_date' => now()->addDays(33)->toDateString(),
                'status' => '1',
            ]
        );

        $lead = Lead::updateOrCreate(
            ['company_name' => 'Acme Infra Pvt Ltd', 'tradefair_id' => $tradefair->id],
            [
                'city' => $city->name,
                'country' => $country->name,
                'fair_name' => $tradefair->fair_name,
                'fair_start_date' => $tradefair->event_start_date,
                'fair_end_date' => $tradefair->event_end_date,
                'booth_area_sqm' => 54,
                'lead_budget' => 15000,
                'email_id' => 'procurement@acmeinfra.com',
                'phone_number' => '+91-9876543210',
                'lead_status' => 'Costing',
            ]
        );

        if ($lead->vendorQuotes()->count() === 0) {
            $lead->vendorQuotes()->createMany([
                [
                    'vendor_name' => 'Vendor A',
                    'vendor_raw_cost' => 5000,
                    'our_markup_percent' => 20,
                    'selection_toggle' => false,
                ],
                [
                    'vendor_name' => 'Vendor B',
                    'vendor_raw_cost' => 5400,
                    'our_markup_percent' => 20,
                    'selection_toggle' => false,
                ],
                [
                    'vendor_name' => 'Vendor C',
                    'vendor_raw_cost' => 4900,
                    'our_markup_percent' => 22,
                    'selection_toggle' => true,
                ],
            ]);
        }
    }
}
