<?php

namespace Modules\User\Http\Controllers;

use App\Http\Controllers\BaseCrudController;
use Illuminate\Http\JsonResponse;
use Modules\User\Entities\Address;
use Modules\User\Http\Requests\AddressRequest;
use Modules\User\Repositories\Contracts\AddressRepositoryInterface;
use Modules\User\Transformers\AddressResource;

class AddressController extends BaseCrudController
{
    protected $modelClass = Address::class;

    protected $resourceClass = AddressResource::class;

    protected $requestClass = AddressRequest::class;

    protected $resourceName = 'address';

    protected $resourceNamePlural = 'addresses';

    public function __construct(
        AddressRepositoryInterface $addressRepository,
    ) {
        parent::__construct($addressRepository);
    }

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

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

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

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