<?php

namespace App\Classes\Modules\PackingLists\ControllersLogic\Containers;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\UpdatesContainerStatus;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\ValueObjects\Constants\ApprovalStatus;

use App\Http\Resources\ContainerResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Carbon\Carbon;

class CompleteContainerLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Updated Container',
            'message' => 'You have successfully updated the Container'
        ];
    }


    /** @var UpdatesContainerStatus */
    private $updatesContainerStatus;

    /** @var FetchesContainer */
    private $fetchesContainer;

    /**
     * CompleteContainerLogic constructor.
     * @param CanUpdateContainer $canUpdateContainer
     * @param UpdatesContainerStatus $updatesContainerStatus
     * @param FetchesContainer $fetchesContainer
     */
    public function __construct(UpdatesContainerStatus $updatesContainerStatus, FetchesContainer $fetchesContainer)
    {
        $this->updatesContainerStatus = $updatesContainerStatus;
        $this->fetchesContainer = $fetchesContainer;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ErrorException
     */
    public function logic(Request $request) : JsonResponse
    {
        $container = $this->fetchesContainer->execute(['id' => $request->route('id')]);
        $query = $this->updatesContainerStatus->execute($container, ApprovalStatus::COMPLETED);
        return $this->resourceResponse(new ContainerResource($container));
    }

}
