<?php

namespace App\Http\Controllers\Api\V1\Product;

use App\Http\Controllers\Api\V1\Product\Resources\ProductIndexResource;
use App\Http\Controllers\Controller;
use App\Repositories\Ecommerce\Product\ProductRepository;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ViewedProductController extends Controller
{
    /**
     * Viewed Products (index)
     */
    public function index(Request $request): JsonResponse
    {
        return response()->rest_paginate(
            ProductIndexResource::collection(
                ProductRepository::make($request)
                    ->applyBasicQueries()
                    ->applyViewedBy(auth('sanctum')->user())
                    ->simplePaginate()
            )
        );
    }
}
