<?php

namespace Modules\User\Http\Controllers;

use App\Http\Controllers\BaseCrudController;
use Illuminate\Http\JsonResponse;
use Modules\User\Entities\Heir;
use Modules\User\Http\Requests\HeirRequest;
use Modules\User\Repositories\Contracts\HeirRepositoryInterface;
use Modules\User\Transformers\HeirResource;

class HeirController extends BaseCrudController
{
    protected $modelClass = Heir::class;

    protected $resourceClass = HeirResource::class;

    protected $requestClass = HeirRequest::class;

    protected $resourceName = 'heir';

    protected $resourceNamePlural = 'heirs';

    public function __construct(
        HeirRepositoryInterface $heirRepository,
    ) {
        parent::__construct($heirRepository);
    }

    protected function prepareStoreData(array $validated): array
    {
        return array_merge($validated, [
            'user_id' => auth()->id(),
        ]);
    }

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

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

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