<?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\TransactionObject;
use App\Models\Booking;
use App\Models\Transaction;

class CreatesTransaction extends AbstractUpdateRelationshipRecord
{
    /**
     * @param TransactionObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Booking $booking, TransactionObject $object) {
        $model = new Transaction();
        $model->bill_no = $object->getBillNo();
        $model->type = $object->getTransactionType();
        $model->issuer = $object->getIssuer();
        $model->receiver = $object->getReceiver();
        $model->recipient_bank_account_id = $object->getRecipientBankAccountId();
        $model->payment_method = $object->getPaymentMethod();
        $model->amount = $object->getAmount();
        $model->original_amount = $object->getOriginalAmount();
        $model->currency_id = $object->getCurrencyId();
        $model->original_currency_id = $object->getOriginalCurrencyId();
        $model->currency_rate = $object->getCurrencyRate();
        $model->tax = $object->getTax();
        $model->service_charge = $object->getServiceCharge();
        $model->expires_on = $object->getExpiresOn();
        $model->status = $object->getStatus();


        return $this->handler($booking->transactions(), $model);

    }
}