<?php

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


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\PackingLists\Services\Packages\SwitchesPackagePackingList;
use App\Classes\Modules\PackingLists\Services\Packages\FetchesPackage;
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
use App\Http\Resources\PackageResource;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class SwitchPackagePackingListLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Switched Package Packing List',
            'message' => 'You have successfully switched the Package Packing List'
        ];
    }

    /** @var SwitchesPackagePackingList */
    private $switchesPackagePackingList;

    /** @var FetchesPackage */
    private $fetchesPackage;

    /** @var FetchesPackingList */
    private $fetchesPackingList;

    /**
     * UpdatePackageLogic constructor.
     * @param SwitchesPackagePackingList $switchesPackagePackingList
     * @param FetchesPackage $fetchesPackage
     * @param FetchesPackingList $fetchesPackingList
     */
    public function __construct(SwitchesPackagePackingList $switchesPackagePackingList, FetchesPackage $fetchesPackage, FetchesPackingList $fetchesPackingList)
    {
        $this->switchesPackagePackingList = $switchesPackagePackingList;
        $this->fetchesPackage = $fetchesPackage;
        $this->fetchesPackingList = $fetchesPackingList;
    }


    /**
     * @param Request $request
     * @return JsonResponse
     * @throws ErrorException
     */
    public function logic(Request $request) : JsonResponse
    {
        $package = $this->fetchesPackage->execute(['id' => $request->route('id')]);

        $packing_list = $this->fetchesPackingList->execute(['id' => $request->input('packing_list_id')]);

        $query = $this->switchesPackagePackingList->execute($package, $packing_list);

        return $this->resourceResponse(new PackageResource($query));
    }

}
