<?php

namespace App\Classes\Modules\Countries\Services;

use App\Classes\General\Eloquent\AbstractUpdateRecord;
use App\Classes\Modules\Countries\DataTransferObjects\CountryObject;
use App\Models\Country;

class CreatesCountry extends AbstractUpdateRecord
{
    /**
     * @param CountryObject $object
     * @return \Illuminate\Database\Eloquent\Model
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(CountryObject $object) {

        $model = new Country();

        return $model->firstOrCreate([
            'name' => $object->getName(),
            'short_code' => $object->getShortCode(),
            'phone_code' => $object->getPhoneCode(),
        ]);

    }
}