<?php

namespace App\Classes\Modules\Contacts\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Interfaces\Contactable;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
use App\Models\Contact;

class CreatesContact extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Contactable $contactable
     * @param ContactObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Contactable $contactable, ContactObject $object)
    {
        $model = new Contact();
        $model->reference = $object->getReference();
        $model->phone = $object->getPhone();
        $model->email = $object->getEmail();
        $model->wechat_id = $object->getWechatId();

        return $this->handler($contactable->contacts(), $model);
    }
}
