<?php

namespace Database\Seeders;

use App\Enum\UserType;
use Illuminate\Database\Seeder;
use App\Models\Vendor;
use App\Models\User;
use Illuminate\Support\Str;

class VendorSeeder extends Seeder
{
    public function run(): void
    {
        // Get or create a user for this vendor
        $user = User::firstOrCreate(
            ['email' => 'vendor.user@4colors.com'],
            [
                'firstname' => 'Vendor',
                'lastname' => 'User',
                'phone' => '+1234567895',
                'password' => bcrypt('vendor123'),
                'status' => 'active',
                'user_type' => UserType::VENDOR->value,
            ]
        );

        // Refresh the user to get the UUID
        $user->refresh();

        // Debug: Check the user ID
        $this->command->info('User ID: ' . $user->id);
        $this->command->info('User UUID type: ' . gettype($user->id));

        Vendor::updateOrCreate(
            ['email' => 'vendor@4colors.com'],
            [
                // Required fields from original migration
                'user_id' => $user->id,
                'business_name' => '4Colors Printing Services',
                'contact_name' => 'John Doe',
                'email' => 'vendor@4colors.com',
                'phone' => '+1234567890',
                'business_address' => '123 Printing Street, Print City, PC 12345',
                'vendor_type' => json_encode(['service_provider', 'material_seller']),

                // Marketplace fields from update migration
                'slug' => '4colors-printing-services',
                'contact_person' => 'John Doe',
                'address' => '123 Printing Street',
                'city' => 'Print City',
                'state' => 'PC',
                'country' => 'Printland',
                'postal_code' => '12345',
                'description' => 'Professional printing services offering high-quality digital and offset printing for all your business needs.',
                'rating' => 4.5,
                'review_count' => 25,
                'logo' => 'vendor-logo.png',
                'website' => 'https://4colors.com',
                'is_verified' => true,
                'is_active' => true,

                // Additional printing service fields
                'print_services' => json_encode(['digital_printing', 'offset_printing', 'large_format', 'screen_printing']),
                'machine_types' => 'Digital presses, Offset printers, Large format printers, Screen printing equipment',
                'turnaround_time' => '2-3 business days',
                'materials_sold' => json_encode(['paper', 'vinyl', 'fabric', 'plastic', 'metal']),
                'minimum_order_qty' => '50',
                'pricing_file' => 'pricing-sheet.pdf',
                'cac_document' => 'cac-certificate.pdf',
                'additional_notes' => 'Specializing in bulk orders with competitive pricing and fast delivery.',
            ]
        );

        // Create a second vendor for testing
        $user2 = User::firstOrCreate(
            ['email' => 'vendor2.user@4colors.com'],
            [
                'firstname' => 'Premium',
                'lastname' => 'Prints',
                'phone' => '+1234567896',
                'password' => bcrypt('vendor123'),
                'status' => 'active',
                'user_type' => UserType::VENDOR->value,
            ]
        );

        // Refresh the user to get the UUID
        $user2->refresh();

        Vendor::updateOrCreate(
            ['email' => 'premium@4colors.com'],
            [
                // Required fields
                'user_id' => $user2->id,
                'business_name' => 'Premium Prints Ltd',
                'contact_name' => 'Jane Smith',
                'email' => 'premium@4colors.com',
                'phone' => '+1234567892',
                'business_address' => '456 Quality Avenue, Print District, PD 67890',
                'vendor_type' => json_encode(['service_provider']),

                // Marketplace fields
                'slug' => 'premium-prints-ltd',
                'contact_person' => 'Jane Smith',
                'address' => '456 Quality Avenue',
                'city' => 'Print District',
                'state' => 'PD',
                'country' => 'Printland',
                'postal_code' => '67890',
                'description' => 'Premium quality printing services with focus on high-end materials and exceptional finish.',
                'rating' => 4.8,
                'review_count' => 150,
                'logo' => 'premium-logo.png',
                'website' => 'https://premiumprints.com',
                'is_verified' => true,
                'is_active' => true,

                // Additional fields
                'print_services' => json_encode(['offset_printing', 'embossing', 'foil_stamping', 'die_cutting']),
                'machine_types' => 'Heidelberg Speedmaster, Komori Lithrone, Embossing machines, Foil stamping equipment',
                'turnaround_time' => '5-7 business days',
                'materials_sold' => json_encode(['premium_paper', 'metallic_foil', 'specialty_substrates']),
                'minimum_order_qty' => '100',
                'pricing_file' => 'premium-pricing.pdf',
                'cac_document' => 'premium-cac.pdf',
                'additional_notes' => 'Specializing in luxury printing for corporate clients and special events.',
            ]
        );
    }
}
