<?php

namespace App\Classes\Modules\Orders\Services\Attachments;


use App\Classes\Modules\Orders\DataTransferObjects\OrderObject;
use App\Classes\Modules\Orders\DataTransferObjects\TrackingNumberObject;
use App\Models\TrackingNumber;

class UpdatesTrackingNumber
{

    /** @var TrackingNumber */
    private $repository;

    /**
     * UpdatesTrackingNumber constructor.
     * @param TrackingNumber $repository
     */
    public function __construct(TrackingNumber $repository)
    {
        $this->repository = $repository;
    }


    /**
     * @param int $orderId
     * @param TrackingNumberObject $trackingNumberObject
     */
    public function execute(int $orderId, TrackingNumberObject $trackingNumberObject){
        $this->repository->updateOrCreate(['order_id' => $orderId, 'type' => $trackingNumberObject->getType()],
            [
                'tracking_no' => $trackingNumberObject->getTrackingNumber(),
                'courier' => $trackingNumberObject->getCourier()
            ]);
    }

}