<?php

namespace App\Classes\Modules\Bookings\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Models\Booking;
use App\Models\Company;

class CreatesBooking extends AbstractUpdateRelationshipRecord
{
    /**
     * @param Company $company
     * @param BookingObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Company $company, BookingObject $object) {

        $model = new Booking();
        $model->service_id = $object->getServiceId();
        $model->bank_id = $object->getTransferableBankId();
        $model->marking = $object->getMarking();
        $model->fix_amount = $object->getFixAmount();
        $model->fix_currency_id = $object->getFixCurrencyId();
        $model->convertible_currency_id = $object->getConvertibleCurrencyId();
        $model->conversion_currency_id = $object->getConversionCurrencyId();

        return $this->handler($company->bookings(), $model);
    }
}