<?php

namespace App\Http\Controllers\Orders;

use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\Orders\DataTransferObjects\TrackingNumberObject;
use App\Classes\Modules\Orders\Processors\WarehouseReceivesOrder;
use App\Classes\Modules\Orders\Services\Attachments\UpdatesTrackingNumber;
use Illuminate\Http\Request;

class BulkReceiveNotesController
{

    /**
     * @param Request $request
     * @param UpdatesTrackingNumber $updatesTrackingNumber
     * @throws InternalServerErrorException
     */
    public function create(Request $request, UpdatesTrackingNumber $updatesTrackingNumber) {

        try{
            foreach ($request->input('orders') as $note){

                $trackingNumberObject = new TrackingNumberObject(0, $note['tracking_number']);
                $updatesTrackingNumber->execute($note['id'], $trackingNumberObject);

                (new WarehouseReceivesOrder($note['id'], $request->input('receive_date')))->execute();
            }
        } catch (\Exception $exception){
            throw new InternalServerErrorException($exception->getMessage());
        }

    }

}