<?php

namespace App\Classes\Modules\Addresses\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Models\Address;
use App\Models\Company;

class CreatesAddress extends AbstractUpdateRelationshipRecord
{

    /**
     * @param Company $company
     * @param AddressObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Company $company, AddressObject $object) {
        $model = new Address();
        $model->street_one = $object->getStreetOne();
        $model->street_two = $object->getStreetTwo();
        $model->country_id = $object->getCountryId();
        $model->state_id = $object->getStateId();
        $model->district_id = $object->getDistrictId();
        $model->postcode = $object->getPostCode();

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

    }
}