<?php

namespace App\Classes\Modules\ControllersLogic\Accounts;


use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
use App\Classes\Modules\Accounts\Services\CreatesUserAccount;
use Illuminate\Http\Request;

class CreateUserLogic
{

    /** @var CreatesUserAccount */
    private $createsUserAccount;

    /**
     * RegisterAccountLogic constructor.
     *
     * @param CreatesUserAccount $createsUserAccount
     */
    public function __construct(
        CreatesUserAccount $createsUserAccount
    ) {
        $this->createsUserAccount = $createsUserAccount;
    }

    /**
     * @param Request $request
     * @return \App\Models\User|null
     * @throws \App\Classes\Modules\Accounts\Exceptions\CannotCreateOrderException
     */
    public function execute(Request $request){
        // the email doesn't exist in the database, so create the user
        $object = new UserObject($request->get('first_name'), $request->get('last_name'),
            $request->get('email'), $request->get('password'), 0, true);


        return $this->createsUserAccount->execute($object);
    }

}