<?php

namespace App\Classes\Modules\AddressBook\Services;


use App\Classes\Modules\AddressBook\DataTransferObjects\AddressBookObject;
use App\Models\AddressBook;

class CreatesAddress
{

    /** @var AddressBook */
    private $repository;

    /**
     * CreatesAddress constructor.
     * @param AddressBook $repository
     */
    public function __construct(AddressBook $repository)
    {
        $this->repository = $repository;
    }


    public function execute(AddressBookObject $object){

        $model = $this->repository->create([
           'type' => 1,
           'reference_id' => $object->getReferenceId(),
           'reference' => $object->getName(),
           'contact' => $object->getPhoneNumber(),
           'street_one' => $object->getStreetOne(),
           'street_two' => $object->getStreetTwo(),
           'city' => $object->getCity(),
           'state' => $object->getState(),
           'post_code' => $object->getPostCode(),
           'country' => $object->getCountry(),
           'default' => $object->isDefault(),
           'billing' => $object->isBilling(),
        ]);

        return $model;
    }

}