<?php

namespace Database\Seeders;

use App\Models\ContactMessage;
use App\Models\Service;
use App\Models\Shipment;
use App\Models\ShipmentEvent;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class DatabaseSeeder extends Seeder
{
    public function run(): void
    {
        User::query()->create([
            'name' => 'Accessway Admin',
            'first_name' => 'Accessway',
            'last_name' => 'Admin',
            'email' => 'admin@accesswaysexpresscourier.com',
            'phone' => '',
            'password' => Hash::make('Admin@12345'),
            'is_admin' => true,
            'role_type' => 'super_admin',
            'status' => 'active',
            'email_verified_at' => now(),
        ]);

        $services = [
            [
                'name' => 'Sea Freight',
                'slug' => 'sea-freight',
                'subtitle' => 'FCL, LCL and project cargo worldwide',
                'icon' => 'ship',
                'excerpt' => 'Accessway Express Courier Services having its strong alliance with shipping companies and global freight partners enables to offer cost effective ocean freight.',
                'body' => '<p>Accessway Express Courier Services and Cargo Services having its strong alliance with shipping companies and global freight partners enables to offer cost effective ocean freight to our customers. Irrespective of the cargo size or type, we can ensure your cargo will reach destination safely and in time.</p>
                <h3>FCL (Full container load)</h3>
                <p>With a setup of contracts with major shipping lines, Accessway Express Courier has the edge of availing competitive rates for full loading of full containers from any of the worldwide ports, ensuring we quickly adapt to your capacity requirements and keep your supply chain at optimal efficiency.</p>
                <h3>LCL (Less than container load)</h3>
                <p>When your stock is not enough for a full container, we offer less-than-container loading across all major ports, providing a cost-effective transportation solution for small and less time-sensitive cargo shipments.</p>
                <h3>NCL (Non containerized load)</h3>
                <p>When cargo is not containerisable, we offer NCL options based on customer preference (shortest transit or most cost effective). Our strong alliance with break bulk, RORO, and multipurpose vessel owners and agents helps us secure the most effective solution for NCL requirements.</p>',
                'features' => [
                    'Full Container Load (FCL)',
                    'Less Than Container Load (LCL)',
                    'Cargo Consolidation Services',
                    'Oversized and Project Cargo',
                    'Cross Trades',
                    'Reliable transit schedules',
                    'All major port coverage',
                    'Door to door service',
                ],
                'sort_order' => 1,
                'is_featured' => true,
            ],
            [
                'name' => 'Land Freight',
                'slug' => 'land-freight',
                'subtitle' => 'Flexible road transport across borders',
                'icon' => 'truck',
                'excerpt' => 'Accessway Express Courier Services land freight services offer a highly flexible and a cost-effective solution to your road transport requirements.',
                'body' => '<p>Accessway Express Courier land freight services offer a highly flexible and cost-effective solution to your road transport requirements. Our road transport service providers are equipped with appropriate country-specific permits, ensuring timely and hassle-free deliveries to their respective destinations.</p>
                <p>Special features include service to most GCC locations and reliable transit schedules, with a single point of contact, regular status updates, and a simplified freight process.</p>',
                'features' => [
                    'Full truckload (FTL)',
                    'Less truckload (LTL)',
                    'Hazardous cargo',
                    'Refrigerated cargo',
                    'Cross-border trades (GCC)',
                    'Reliable transit schedules',
                ],
                'sort_order' => 2,
                'is_featured' => true,
            ],
            [
                'name' => 'Air Freight',
                'slug' => 'air-freight',
                'subtitle' => 'Fast transits with major carriers',
                'icon' => 'plane',
                'excerpt' => 'Accessway Express Courier Services provides national delivery services, with daily arrivals into United States airport from the world\'s leading industrial markets.',
                'body' => '<p>Accessway Express Courier Services provides national and international air delivery services, with daily arrivals from the world\'s leading industrial markets.</p>
                <p>We appreciate that air freight can be a premium and costly service, so we focus on fast transits and regular communication combined with the ability to exploit cost-saving opportunities for all of our customers. Liaising closely with all the major carriers and a network of agents, we collect and deliver worldwide door-to-door, providing all the necessary documentation and customs requirements.</p>
                <h3>Air Charter</h3>
                <p>We deliver reliable and cost-effective air cargo charter services. We analyze route, payload and timescale in order to propose the most suitable aircraft for your requirements. We offer part-charters, backloads and other commercially innovative solutions for ad hoc, peak season and project cargo.</p>
                <p>We can provide pre-flight advice on packaging requirements, customs and warehousing, and supervise aircraft loading and unloading. We also coordinate arrangements for specialist equipment, including cranes and custom-built loading structures.</p>',
                'features' => [
                    'Heavy and outsize pieces',
                    'Oil and gas equipment',
                    'Automotive cargo',
                    'High value commodities',
                    'Aerospace equipment',
                    'Humanitarian relief cargo',
                    'Dangerous goods',
                    'Aircraft on Ground (AOG)',
                ],
                'sort_order' => 3,
                'is_featured' => true,
            ],
            [
                'name' => 'Guarding Services',
                'slug' => 'guarding-services',
                'subtitle' => 'Secure handling for high-value cargo',
                'icon' => 'shield',
                'excerpt' => 'Our Security provides guarding services for a variety of events such as high-profile occasions and high-value showings.',
                'body' => '<p>Whether it is a stand-alone warehousing service or combining it with other services to serve your needs, Accessway Express Courier can provide a totally integrated solution. You can count on our services team to handle your problems as well as your products.</p>
                <p>The scope of our service is commonly classified in inventory management, warehousing, transport, and courier. Our services help clients understand their current issues and ensure cost-effective warehousing services with benchmarked customer service levels. We help clients move or consolidate current facilities and operations.</p>
                <p>Our security team also provides guarding services for a variety of events such as high-profile occasions and high-value showings.</p>',
                'features' => [
                    'Inventory management',
                    'Secure warehousing',
                    'High-value cargo guarding',
                    'Event security support',
                    'Facility consolidation',
                ],
                'sort_order' => 4,
                'is_featured' => false,
            ],
            [
                'name' => 'Custom Clearance',
                'slug' => 'custom-clearance',
                'subtitle' => 'Proactive cross-border compliance',
                'icon' => 'clipboard',
                'excerpt' => 'We simplify and ease cross-border trade with in-house customs professionals and local clearance experts.',
                'body' => '<p>Customs rules and processes can be tedious and time consuming if not handled appropriately. Moreover, duty rates and entry processes differ from country to country. Due to regular regularization in customs and security, international trade is now more challenging.</p>
                <p>Our customs clearance consultancy division always strives to simplify and ease cross-border trade. We chalk out every possible delay and take proactive measures to avoid delay in the clearance process. We reassure practice of industry standards and compliance of customs rules.</p>
                <p>Our in-house customs professionals and association with local customs clearance experts mean we know of any change in procedures and keep you informed about the prevailing rules and regulations, allowing you to make well-informed decisions with minimum lead time.</p>',
                'features' => [
                    'Air freight clearance',
                    'Sea freight clearance',
                    'Land clearance',
                    'Temporary import & return',
                    'Repairs and return',
                    'Direct delivery',
                    'Fairs and exhibitions',
                    'Time critical and sensitive cargo',
                ],
                'sort_order' => 5,
                'is_featured' => false,
            ],
            [
                'name' => 'Airline Security',
                'slug' => 'airline-security',
                'subtitle' => 'Aviation safeguarding and relocation',
                'icon' => 'lock',
                'excerpt' => 'Trained officers proficient in safeguarding aviation installations from unauthorized interference, meeting ICAO requirements.',
                'body' => '<p>Given the upsurge of global terrorism especially on airlines and their operations, our company has trained its security officers proficiently in combat and safeguarding all aviation installations from unauthorized interference. We guarantee the highest standard in safeguarding aviation installations by ensuring the requirements of ICAO are applied at all times.</p>
                <p>The company has also been built by professionals with knowledge in the relocation industry. We are associated with several international global agents who are certified to handle clearance and delivery of goods to various destinations. We strive to provide the highest possible customer service, which is why most of our customers come through recommendation.</p>
                <p>Planning your relocation is an important step to a positive experience. Our consultants are equipped with knowledge of country regulations, prohibited lists of goods, and possible extra charges to consider when moving to specific destinations. There are no surprises in the end when using our service.</p>',
                'features' => [
                    'International & domestic removal services',
                    'Office moving',
                    'Relocation services',
                    'Vehicle shipping',
                    'Storage solutions',
                    'Commercial logistics',
                    'ICAO-aligned aviation security',
                ],
                'sort_order' => 6,
                'is_featured' => false,
            ],
        ];

        foreach ($services as $service) {
            Service::query()->create($service);
        }

        $sea = Service::where('slug', 'sea-freight')->first();
        $air = Service::where('slug', 'air-freight')->first();
        $land = Service::where('slug', 'land-freight')->first();

        $shipments = [
            [
                'tracking_number' => 'AEC26001842',
                'service_id' => $air->id,
                'status' => 'in_transit',
                'current_location' => 'Heathrow Cargo Hub, London',
                'sender_name' => 'James Whitmore',
                'sender_email' => 'james.whitmore@example.com',
                'sender_phone' => '+44 20 7946 0123',
                'sender_address' => '14 Canary Wharf, London E14 5AB',
                'origin_city' => 'London',
                'origin_country' => 'United Kingdom',
                'receiver_name' => 'Amelia Chen',
                'receiver_email' => 'amelia.chen@example.com',
                'receiver_phone' => '+1 212 555 0198',
                'receiver_address' => '88 Pine Street, New York, NY 10005',
                'destination_city' => 'New York',
                'destination_country' => 'United States',
                'package_description' => 'Commercial documents and sample textiles',
                'weight_kg' => 12.40,
                'pieces' => 2,
                'ship_date' => now()->subDays(3)->toDateString(),
                'expected_delivery' => now()->addDays(2)->toDateString(),
                'arrival_at' => now()->addDays(2)->setTime(10, 10),
                'progress_percent' => 12,
                'consignment_no' => 'Accessway Express Courier',
                'service_type' => 'Parcel',
                'delivery_mode' => 'COURIER',
                'comment' => 'Notice: Note: The receiver is expected to pay the clearance fee as soon as the parcel arrives in the United States.',
                'events' => [
                    ['picked_up', 'Canary Wharf, London', 'Package collected from sender.', now()->subDays(3)->setTime(9, 20)],
                    ['processing', 'Accessway London Depot', 'Shipment processed, labelled and weighed.', now()->subDays(3)->setTime(13, 10)],
                    ['in_transit', 'Heathrow Cargo Hub, London', 'Departed origin facility. In transit to destination hub.', now()->subDays(1)->setTime(18, 45)],
                ],
            ],
            [
                'tracking_number' => 'AEC26001907',
                'service_id' => $sea->id,
                'status' => 'at_customs',
                'current_location' => 'Port of Felixstowe',
                'sender_name' => 'Nordic Trade AB',
                'sender_email' => 'ops@nordictrade.example',
                'sender_phone' => '+46 8 555 2211',
                'sender_address' => 'Hamngatan 2, Stockholm',
                'origin_city' => 'Stockholm',
                'origin_country' => 'Sweden',
                'receiver_name' => 'Lagos Import Partners',
                'receiver_email' => 'receiving@lagosimport.example',
                'receiver_phone' => '+234 1 270 4400',
                'receiver_address' => 'Apapa Port Complex, Lagos',
                'destination_city' => 'Lagos',
                'destination_country' => 'Nigeria',
                'package_description' => 'Industrial spare parts, 1 x 20ft container',
                'weight_kg' => 1840.00,
                'pieces' => 18,
                'ship_date' => now()->subDays(18)->toDateString(),
                'expected_delivery' => now()->addDays(9)->toDateString(),
                'events' => [
                    ['picked_up', 'Stockholm warehouse', 'Container loaded and sealed.', now()->subDays(18)->setTime(8, 0)],
                    ['in_transit', 'Gothenburg Port', 'Vessel departed for UK transhipment.', now()->subDays(14)->setTime(16, 30)],
                    ['at_customs', 'Port of Felixstowe', 'Arrived transhipment port. Customs documentation in progress.', now()->subDays(2)->setTime(11, 15)],
                ],
            ],
            [
                'tracking_number' => 'AEC26002011',
                'service_id' => $land->id,
                'status' => 'delivered',
                'current_location' => 'Manchester, United Kingdom',
                'sender_name' => 'Claire Osborne',
                'sender_email' => 'claire.osborne@example.com',
                'sender_phone' => '+44 161 496 0101',
                'sender_address' => '22 Deansgate, Manchester',
                'origin_city' => 'Manchester',
                'origin_country' => 'United Kingdom',
                'receiver_name' => 'Henri Dubois',
                'receiver_email' => 'henri.dubois@example.com',
                'receiver_phone' => '+33 1 42 68 5300',
                'receiver_address' => '11 Rue de Rivoli, Paris',
                'destination_city' => 'Paris',
                'destination_country' => 'France',
                'package_description' => 'Retail cartons — seasonal merchandise',
                'weight_kg' => 86.50,
                'pieces' => 6,
                'ship_date' => now()->subDays(8)->toDateString(),
                'expected_delivery' => now()->subDays(1)->toDateString(),
                'events' => [
                    ['picked_up', 'Manchester depot', 'Consignment collected.', now()->subDays(8)->setTime(10, 0)],
                    ['in_transit', 'Dover freight terminal', 'Cross-channel departure confirmed.', now()->subDays(6)->setTime(21, 40)],
                    ['out_for_delivery', 'Paris distribution centre', 'Out for final delivery.', now()->subDays(1)->setTime(7, 55)],
                    ['delivered', '11 Rue de Rivoli, Paris', 'Delivered and signed by receiver.', now()->subDays(1)->setTime(14, 22)],
                ],
            ],
        ];

        foreach ($shipments as $row) {
            $events = $row['events'];
            unset($row['events']);
            $shipment = Shipment::query()->create($row);

            foreach ($events as [$status, $location, $description, $at]) {
                ShipmentEvent::query()->create([
                    'shipment_id' => $shipment->id,
                    'status' => $status,
                    'location' => $location,
                    'description' => $description,
                    'event_at' => $at,
                ]);
            }
        }

        ContactMessage::query()->create([
            'name' => 'Michael Bradly',
            'email' => 'michael.bradly@example.com',
            'phone' => '+1 415 555 0177',
            'subject' => 'Air freight quote',
            'message' => 'Please send a quote for a 24kg parcel from San Francisco to London, door to door.',
            'is_read' => false,
        ]);
    }
}
