<?php

namespace Modules\Address\Repositories;


use Modules\Address\Interfaces\AddressRepositoryInterface;
use Modules\Address\Models\Address;

class AddressRepository implements AddressRepositoryInterface
{
    public function get(array $request)
    {
        $builder = Address::query();
        return $builder;
    }

    public function getItem(int $id)
    {
        return Address::find($id);
    }

    public function checkItem(int $id)
    {
        return Address::find($id);
    }


    public function getItemTrashed(int $id)
    {
        $address = Address::onlyTrashed()->find($id);
        return $address;
    }



    public function create(array $request): Address
    {
        $address = Address::create($request);
        return $address;
    }

    public function update(array $request, ?Address $address): Address
    {
        $address->update($request);

        return $address;
    }


    /**
     * Remove the specified address from storage.
     * @param Address $address
     * @return void
     */
    public function destroy(Address $address): void
    {
        $address->delete();
    }

    /**
     * Remove several addresses by IDs.
     *
     * @param array $request
     * @return void
     */
    public function destroyAll(array $ids): void
    {
        Address::whereIn('id', $ids)->delete();
    }

    /**
     * Restore the specified address from storage.
     *
     * @param Address $address
     * @return void
     */
    public function restore(Address $address): void
    {
        $address->restore();
    }

    /**
     * Restore several addresses by IDs.
     *
     * @param array $request
     * @return void
     */
    public function restoreAll(array $ids): void
    {
        Address::whereIn('id', $ids)->onlyTrashed()->restore();
    }
}
