<?php

namespace App\Classes\Modules\Contacts\Services;


use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Models\Contact;

class UpdateContact
{
    /** @var  Contact */
    private $repository;

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


    /**
     * @param int $id
     * @param ContactObject $object
     * @return Contact
     */
    public function execute(int $id, ContactObject $object)
    {
        /** @var Contact $contact */
        $contact = $this->repository->findOrFail($id);
        $contact ->name = $object->getName();
        $contact ->designation = $object->getDesignation();
        $contact ->contact = $object->getContact();
        $contact ->email = $object->getEmail();

        $contact->save();

        return $contact;

    }

}