<?php

namespace App\Classes\Modules\Addresses\ControllersLogic;


use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Addresses\Services\DeletesAddress;
use App\Classes\Modules\Addresses\Services\FetchesAddress;
use App\Classes\Modules\Addresses\Standards\Rules\CanDeleteAddress;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteAddressLogic extends AbstractControllerLogic
{
    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Deleted Address',
            'message' => 'You have successfully deleted a Address'
        ];
    }


    /** @var CanDeleteAddress */
    private $canDeleteAddress;

    /** @var DeletesAddress */
    private $deletesAddress;

    /** @var FetchesAddress */
        private $fetchesAddress;

    /**
     * DeleteAddressControllersLogic constructor.
     * @param CanDeleteAddress $canDeleteAddress
     * @param DeletesAddress $deletesAddress
     * @param FetchesAddress $fetchesAddress
     */
    public function __construct(CanDeleteAddress $canDeleteAddress, DeletesAddress $deletesAddress, FetchesAddress $fetchesAddress)
    {
        $this->canDeleteAddress = $canDeleteAddress;
        $this->deletesAddress = $deletesAddress;
        $this->fetchesAddress = $fetchesAddress;
    }


    /**
     * @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
    {

        $this->canDeleteAddress->passes();

        $query = $this->fetchesAddress->execute(['id' => $request->route('id')]);

        $this->deletesAddress->execute($query);

        return $this->response([]);

    }

}