<?php

namespace Database\Seeders;

use App\Classes\Jobs\FetchContainersStatusUpdateFromVTPortalJob;
use App\Classes\Jobs\FetchDeliveryListFromVTPortalJob;
use App\Classes\Jobs\FetchLoadedContainersFromVTPortalJob;
use App\Classes\Jobs\FetchPackingListFromVTPortalJob;
use App\Classes\Jobs\FetchWarehouseReceiveListFromVTPortalJob;
use App\Classes\Modules\PackingLists\Processors\FetchContainersStatusUpdateFromVTPortalProcessor;
use App\Models\Address;
use App\Models\Container;
use App\Models\ContainerPackingList;
use App\Models\OldOrders;
use App\Models\Order;
use App\Models\Package;
use App\Models\PackingList;
use App\Models\Schedule;
use App\Models\Step;
use App\Models\Transport;
use Illuminate\Database\Seeder;

class DeleteOldOrdersSeeder extends Seeder
{


    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Container::truncate();
        ContainerPackingList::truncate();
        Transport::truncate();
        Schedule::truncate();
        PackingList::truncate();
        Package::truncate();
        Step::truncate();

        foreach (Order::all() as $order){
            $oldOrder = OldOrders::where('marking', '=', $order->reference)->first();
            if($oldOrder){
                $order->addresses()->forceDelete();
                $order->packingLists()->forceDelete();
                $order->OrderRoles()->forceDelete();
                $order->orderSteps()->forceDelete();
                $order->forceDelete();
            }
        }
    }

}
