<?php

namespace App\Http\Controllers;

use App\Models\RecruiterProfile;
use App\Repositories\Contracts\RecruiterProfileRepositoryInterface;
use App\Http\Traits\ResponseTrait;
use App\Http\Resources\ResponseCollection;
use Illuminate\Http\Request;

class RecruiterProfileController extends Controller
{
    use ResponseTrait;

    private $recruiterRepository;

    public function __construct(RecruiterProfileRepositoryInterface $recruiterRepository)
    {
        $this->recruiterRepository = $recruiterRepository;
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $perPage = $request->per_page ? $request->per_page : 100;

        return new ResponseCollection(
            $this->paginateResponse($this->recruiterRepository->all($request), $perPage)
        );
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        // $request->validate([
        //     'name' => 'required|string|max:255',
        //     'location' => 'required|string|max:255',
        //     'owner_id' => 'required|numeric',
        // ]);

        $recruiter = $this->recruiterRepository->create($request->toArray());

        return $this->successResponse($recruiter, 'Recruiter added successfully!');
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Recruiter  $recruiter
     * @return \Illuminate\Http\Response
     */
    public function show(Recruiter $recruiter)
    {
        return $this->successResponse($recruiter);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Recruiter  $recruiter
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Recruiter $recruiter)
    {
        $this->recruiterRepository->update($recruiter, $request->toArray());

        return $this->updateResponse('Recruiter updated successfully!');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Recruiter  $recruiter
     * @return \Illuminate\Http\Response
     */
    public function destroy(Recruiter $recruiter)
    {
        $this->recruiterRepository->delete($recruiter);

        return $this->updateResponse('Recruiter deleted successfully!');
    }
}
