<?php

namespace App\Classes\Modules\Rewards\ControllersLogic;

use App\Http\Resources\RewardResource;

use App\Classes\General\Abstracts\AbstractControllerLogic;

use App\Classes\Modules\Rewards\Services\FetchesReward;

use App\Classes\Modules\Rewards\Standards\Rules\CanDeleteReward;
use App\Classes\Modules\Rewards\Services\DeletesReward;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class DeleteRewardLogic extends AbstractControllerLogic
{

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

    /** @var CanDeleteReward */
    private $canDeleteReward;

    /** @var DeletesReward */
    private $deletesReward;

    /** @var FetchesReward */
    private $fetchesReward;


    /**
     * DeleteRewardLogic constructor.
     * @param CanDeleteReward $canDeleteReward
     * @param DeletesReward $deletesReward
     * @param FetchesReward $fetchesReward
     */
    public function __construct(
        CanDeleteReward $canDeleteReward,
        DeletesReward $deletesReward,
        FetchesReward $fetchesReward
    )
    {
        $this->canDeleteReward = $canDeleteReward;
        $this->deletesReward = $deletesReward;
        $this->fetchesReward = $fetchesReward;
    }

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

        $query = $this->fetchesReward->execute(['id' => $request->route('id')]);
        $this->canDeleteReward->passes();
        $this->deletesReward->execute($query);

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

}
