<?php

namespace App\Classes\Modules\Currencies\Services\Rates;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Currencies\DataTransferObjects\RateObject;
use App\Models\Currency;
use App\Models\CurrencyRate;

class CreatesRate extends AbstractUpdateRelationshipRecord
{

    /**
     * @param Currency $currency
     * @param RateObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Currency $currency, RateObject $object)
    {
        $model = new CurrencyRate();
        $model->selling = $object->getSelling();
        $model->payment_method_type = $object->getPaymentMethodType();
        $model->service_id = $object->getServiceId();

        return $this->handler($currency->rates(), $model);
    }
}