<?php

namespace App\Classes\Modules\Banks\ControllersLogic;

use App\Http\Resources\BankResource;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Banks\Services\FetchesBank;
use App\Classes\Modules\Banks\Services\UpdatesBankStatus;
use App\Classes\Modules\Banks\Services\CreatesBankLog;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UpdateBankStatusLogic extends AbstractControllerLogic
{

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

    /** @var FetchesBank */
    private $fetchesBank;

    /** @var UpdatesBankStatus */
    private $updatesBankStatus;

    /** @var CreatesBankLog */
    private $createsBankLog;

    /**
     * UpdateBankStatusLogic constructor.
     * @param FetchesBank $fetchesBank
     * @param UpdatesBankStatus $updatesBankStatus
     * @param CreatesBankLog $createsBankLog
     */
    public function __construct(
        FetchesBank $fetchesBank,
        UpdatesBankStatus $updatesBankStatus,
        CreatesBankLog $createsBankLog
    )
    {
        $this->fetchesBank = $fetchesBank;
        $this->updatesBankStatus = $updatesBankStatus;
        $this->createsBankLog = $createsBankLog;
    }

    /**
     * @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
    {
        $bank = $this->fetchesBank->execute(['id' => $request->route('id')]);

        $bank_query = $this->updatesBankStatus->execute($bank, $request->input('status'));

        $bankLog = $this->createsBankLog->execute($bank_query);

        return $this->resourceResponse(new BankResource($bank_query));

    }

}