<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserGenerate extends AbstractController
{

    public function users(Request $request)
    {
        $zoom = $this->zoom($request);
        $user = new \MacsiDigital\Zoom\User($zoom);
        return response()->json($user->all());
    }


    public function invitation(Request $request)
    {
        #email required
        if (!$request->get('name'))
        {
            return response()->json(['error' => 'Name is required'], 422);
        }

        if (!$request->get('surname'))
        {
            return response()->json(['error' => 'Surname is required'], 422);
        }

        if (!$request->get('email'))
        {
            return response()->json(['error' => 'Email is required'], 422);
        }

        if (!$request->get('password'))
        {
            return response()->json(['error' => 'Password'], 422);
        }

        $email = $request->get('email');
        $zoom = $this->zoom($request);
        $user = new \MacsiDigital\Zoom\User($zoom);

        $result = $user->create([
            'first_name' => $request->get('name'),
            'last_name' => $request->get('surname'),
            'email' => $email,
            'password' =>   $request->get('password'),
        ]);

        return response()->json($result);
    }
}
