<?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\ListsBanks;

use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBank;
use App\Classes\Modules\Banks\Services\ResetsBanksDefault;
use App\Classes\Modules\Banks\Services\SetsBankToDefault;

use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
use App\Classes\ValueObjects\Constants\DefaultType;

use App\Models\Bank;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class SetBankToDefaultLogic extends AbstractControllerLogic
{

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

    /** @var ResetsBanksDefault */
    private $resetsBanksDefault;

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

    /** @var SetsBankToDefault*/
    private $setsBankToDefault ;

    /**
     * SetBankToDefaultLogic constructor.
     * @param ResetsBanksDefault $resetsBanksDefault
     * @param FetchesBank $fetchesBank
     * @param SetsBankToDefault $setsBankToDefault
     */
    public function __construct(ResetsBanksDefault $resetsBanksDefault, FetchesBank $fetchesBank, SetsBankToDefault $setsBankToDefault)
    {
        $this->resetsBanksDefault = $resetsBanksDefault;
        $this->fetchesBank = $fetchesBank;
        $this->setsBankToDefault = $setsBankToDefault;
    }

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

        /** @var Bank $bank */
        $bank = $this->fetchesBank->execute(['id' => $request->route('id')]);

        $this->resetsBanksDefault->execute($bank);

        $this->setsBankToDefault->execute($bank);

        return $this->resourceResponse(new BankResource($this->setsBankToDefault->execute($bank)));
    }

}