<?php

namespace App\Classes\Modules\Addresses\Services;

use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
use App\Classes\General\Interfaces\Addressable;
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Models\Address;
use App\Models\CompanyModule;

class CreatesAddress extends AbstractUpdateRelationshipRecord
{

    /**
     * @param Addressable $addressable
     * @param AddressObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Addressable $addressable, AddressObject $object) {

        $model = new Address();

        $model->reference = $object->getReference();
        $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();
        $model->status = $object->getStatus();

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

    }
}