<?php

namespace App\Classes\Modules\ControllersLogic\Orders;

use App\Classes\Modules\ControllerLogic\Exceptions\InternalServerErrorException;
use App\Classes\Modules\Orders\DataTransferObjects\AddressObject;
use App\Classes\Modules\Orders\Services\UpdatesOrderAddress;
use App\Classes\ValueObjects\Constants\HttpStatus;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateOrderAddressLogic
{
    /** @var  UpdatesOrderAddress */
    private $UpdatesOrderAddress;

    /**
     * UpdateOrderAddressLogic constructor.
     * @param UpdatesOrderAddress $UpdatesOrderAddress
     */
    public function __construct(UpdatesOrderAddress $UpdatesOrderAddress)
    {
        $this->UpdatesOrderAddress = $UpdatesOrderAddress;
    }

    public function execute(string $orderId, Request $request){
        try{

            return $this->UpdatesOrderAddress->execute($orderId,$request->address_id);
            return new JsonResponse([],HttpStatus::REQUEST_ACCEPTED);

        } catch (\Exception $exception) {
            throw new InternalServerErrorException("Failed to update address because{$exception->getMessage()}");
        }
    }

}