<?php

namespace Modules\User\Repositories;

use Illuminate\Http\Request;
use Modules\User\Interfaces\AddressRepositoryInterface;
use Modules\User\Models\Address;

class AddressRepository implements AddressRepositoryInterface
{
    public function get(array $request)
    {
        $addresses = Address::with(['city','region','country'])->orderBy('id', 'DESC');

        return $addresses;
    }

    public function getItem(int $id)
    {
        return Address::with(['city','region','country'])->find($id);
    }

    public function checkItem(int $id)
    {
        return Address::with(['city','region','country'])->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 addresss 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 addresss by IDs.
     *
     * @param array $request
     * @return void
     */
    public function restoreAll(array $ids) :void
    {
        Address::whereIn('id', $ids)->onlyTrashed()->restore();
    }
}
