<?php

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


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Containers\FetchesContainer;
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
use App\Http\Resources\ContainerResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class CreateContainerRemarkLogic extends AbstractControllerLogic
{


    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Created Container',
            'message' => 'You have successfully created a new Container'
        ];
    }


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

    /** @var CreateRemarkProcessor */
    private $createRemarkProcessor;

    /**
     * CreateContainerRemarkLogic constructor.
     * @param FetchesContainer $fetchesContainer
     * @param CreateRemarkProcessor $createRemarkProcessor
     */
    public function __construct(FetchesContainer $fetchesContainer, CreateRemarkProcessor $createRemarkProcessor)
    {
        $this->fetchesContainer = $fetchesContainer;
        $this->createRemarkProcessor = $createRemarkProcessor;
    }

    /**
     * @param Request $request
     * @return JsonResponse
     * @throws \App\Classes\Exceptions\AccessForbiddenException
     * @throws \App\Classes\Exceptions\MalformedRequestException
     * @throws \App\Classes\Exceptions\RequestValidationException
     */
    public function logic(Request $request) : JsonResponse
    {

        $container = $this->fetchesContainer->execute(['id' => $request->route('id')]);

        $object = new RemarkObject($request->input('content'), auth()->user()->id);

        $this->createRemarkProcessor->execute($container, $object);

        return $this->resourceResponse(new ContainerResource($container));

    }

}
