<?php

namespace App\Http\Controllers;

use App\Models\AiReview;
use App\Repositories\Contracts\AiReviewRepositoryInterface;
use App\Http\Traits\ResponseTrait;
use App\Http\Resources\ResponseCollection;
use Illuminate\Http\Request;

class AiReviewController extends Controller
{
    use ResponseTrait;

    private $aiReviewRepository;

    public function __construct(AiReviewRepositoryInterface $aiReviewRepository)
    {
        $this->aiReviewRepository = $aiReviewRepository;
    }

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

        $aiReview = $this->aiReviewRepository->create($request->toArray());

        return $this->successResponse($aiReview, 'Ai Review added successfully!');
    }

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

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

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

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

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