<?php

namespace App\Classes\Modules\Notifications\Services;

use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject;
use App\Models\Notification;

class CreatesNotification
{
    /**
     * @param NotificationObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(NotificationObject $object) {
        $model = new Notification();
        $model->title = $object->getTitle();
        $model->description = $object->getDescription();
        $model->status = $object->getStatus();
        $model->subject_type = get_class($object->getSubject());
        $model->subject_id = $object->getSubject()->id;
        $model->target_type = get_class($object->getTarget());
        $model->target_id = $object->getTarget()->id;
        $model->causer_type = get_class($object->getCauser());
        $model->causer_id = $object->getCauser()->id;
        $model->save();

        return $model;
    }
}