<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\ReviewService;
use App\Traits\ApiResponse;
use Illuminate\Http\Request;

class ReviewController extends Controller
{
    use ApiResponse;

    protected $reviewService;

    public function __construct(ReviewService $reviewService)
    {
        $this->reviewService = $reviewService;
    }

    public function getProductReviewItem($orderId)
    {
        try {
            $data = $this->reviewService->getProductReviewItem($orderId);
            return $this->successResponse($data, 'Fetching product review item successfully');
        } catch(\Exception $e) {
            return $this->errorResponse('Failed to fetch product review item', 400, $e->getMessage());
        }
    }

    public function reviewProduct(Request $request, $orderId)
    {
        try {
            $this->reviewService->reviewProduct($request->all(), $orderId);
            return $this->successResponse(null, 'Review product successfully');
        } catch(\Exception $e) {
            return $this->errorResponse('Failed to review product', 400, $e->getMessage());
        }
    }
}
