<?php

namespace App\Classes\Modules\AddressBook\Services;

use App\Models\Company;
use App\Http\Resources\AddressBook as AddressBookResource;

class DeletesAddressBook
{
    /** @var  Company */
    private $repository;

    /**
     * DeletesAddressBook constructor.
     * @param Company $repository
     */
    public function __construct(Company $repository)
    {
        $this->repository = $repository;
    }


    public function execute(String $companyId, String $id){

        $address = $this->repository->findOrFail($companyId)->addressBook()->findOrFail($id);

        if($address->delete()){

            // Return single address as a resource
            return new AddressBookResource($address);

        }
    }

}