<?php

namespace App\Classes\Modules\Transactions\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
use App\Models\Transaction;
use App\Models\TransactionDetail;

class CreatesTransactionDetail extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Transaction $transaction
     * @param TransactionDetailObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Transaction $transaction, TransactionDetailObject $object) {
        $model = new TransactionDetail();
        $model->product_code = $object->getCode();
        $model->product_name = $object->getName();
        $model->quantity = $object->getQuantity();
        $model->price = $object->getPrice();
        $model->amount = $object->getAmount();

        return $this->handler($transaction->transactionDetails(), $model);

    }
}