<?php

namespace App\Http\Controllers;
use App\Services\ProfessionalService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;
use App\Http\Traits\Desxpert;

class ProfessionalController extends Controller
{
    use Desxpert;

    protected $professionalService;

    public function __construct(ProfessionalService $professionalService)
    {
        $this->professionalService = $professionalService;
        $this->route = 'professionals';
        $this->view = 'professionals';
    }

    public function index()
    {
        $professionals = $this->professionalService->getAllProfessionals();
        $loggedUser = $this->loggedUser();
        return view($this->view.'.index', compact('professionals','loggedUser'));

    }
    public function getByProfession($id)
    {
        $professionals = $this->professionalService->getByProfession($id);

        return Response::json($professionals);
    }

    public function viewProfile($id)
    {
        $response = $this->professionalService->viewProfile($id);
        return $response;
    }
    public function viewApplication($id)
    {
        $application = $this->professionalService->viewApplication($id);
        return view($this->view.'.application', compact('application'));
    }

    public function updateStatus(Request $request, $id)
    {
        $response = $this->professionalService->updateStatus($id, $request->status);
        return redirect($this->route)->with($response['status'], $response['message']);
    }

}
