<?php

namespace Modules\User\Http\Controllers;

use App\Http\Controllers\BaseCrudController;
use Illuminate\Http\JsonResponse;
use Modules\User\Entities\Bank;
use Modules\User\Http\Requests\BankRequest;
use Modules\User\Repositories\Contracts\BankRepositoryInterface;
use Modules\User\Transformers\BankResource;

class BankController extends BaseCrudController
{
    protected $modelClass = Bank::class;

    protected $resourceClass = BankResource::class;

    protected $requestClass = BankRequest::class;

    protected $resourceName = 'bank';

    protected $resourceNamePlural = 'banks';

    public function __construct(
        BankRepositoryInterface $bankRepository,
    ) {
        parent::__construct($bankRepository);
    }

    protected function prepareStoreData(array $validated): array
    {
        return $validated;
    }

    protected function getItemName($item): string
    {
        return $item->name ?? $item->id;
    }

    protected function prepareUpdateData(array $validated, $bank): array
    {
        return $validated;
    }

    protected function checkDependencies($bank): ?JsonResponse
    {
        return null;
    }

    public function active(): JsonResponse
    {
        $banks = $this->repository->active();

        return response()->json([
            'success' => true,
            'data' => $this->resourceClass::collection($banks),
        ]);
    }
}