<?php

namespace App\Http\Controllers;

use App\Models\RecruiterSubscription;
use App\Repositories\Contracts\RecruiterSubscriptionRepositoryInterface;
use App\Http\Traits\ResponseTrait;
use App\Http\Resources\ResponseCollection;
use Illuminate\Http\Request;

class RecruiterSubscriptionController extends Controller
{
    use ResponseTrait;

    private $recruiterSubscriptionRepository;

    public function __construct(RecruiterSubscriptionRepositoryInterface $recruiterSubscriptionRepository)
    {
        $this->recruiterSubscriptionRepository = $recruiterSubscriptionRepository;
    }

    /**
     * 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->recruiterSubscriptionRepository->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',
        // ]);

        $recruiterSubscription = $this->recruiterSubscriptionRepository->create($request->toArray());

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

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

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

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

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

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