<?php

namespace App\Http\Controllers;

use App\Interfaces\UserRepositoryInterface;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class UserJobController extends Controller
{
    private UserRepositoryInterface $userRepository;
    public function __construct(UserRepositoryInterface $userRepository)
    {
        $this->middleware('auth:api');
        $this->userRepository = $userRepository;
    }

    //Get Job Profile
    public function index(Request $request)
    {
        try {
            $user = Auth::user();
            $profile = $this->userRepository->getJobProfile($user->id);

            return response()->json([
                'status' => 'success',
                'message' => 'Profile returned successfully',
                'data' => $profile
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'status' => 'failed',
                'message' => $e->getMessage(),
            ], 500);
        }
    }


    

    public function updateProfile(Request $request)
    {
        try {
          
            $id = $request->id;

            $profile = $this->userRepository->updateJobProfile($id, $request->all());
            return response()->json([
                'status' => 'success',
                'message' => 'Job info updated successfully',
                'data' => $profile
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'status' => 'failed',
                'message' => $e->getMessage(),
            ], 500);
        }
    }
}
