<?php

namespace App\Http\Controllers\API\Sales\Outlet;

use App\Http\Controllers\Controller;
use App\OutletClient;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use JWTAuth;

class IndexController extends Controller
{
    public function createNewClient(Request $request)
    {
        $outlet = new OutletClient();
        $outlet->name = $request->name;
        $outlet->address = $request->address;
        $outlet->phone = $request->phone;
        $outlet->sales = JWTAuth::parseToken()->authenticate()->id;
        $outlet->save();

        $user = new User();
        $user->name = $outlet->name;
        $user->id_employee = $outlet->phone;
        $user->email = $outlet->phone.'@email.com';
        $user->role_id = 5;
        $user->password = Hash::make($request->phone);
        $user->save();

        return response('Data berhasil di simpan!', 200);
    }

    public function getClient()
    {
        $client = OutletClient::all();
        return response($client, 200);
    }
}
