<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use App\Http\Resources\CompilationResource;
use App\Http\Resources\ProductPaginationResource;
use App\Models\Compilation;
use App\Models\Currency;

class CompilationController extends Controller
{
    public function index()
    {
        $compilations = Compilation::where('published', 1)->get();

        $currency = Currency::latest()->first();
        // add currency to cache
        cache()->put('currency', $currency, now()->addMinutes(60));

        return CompilationResource::collection($compilations);
    }

    public function show($id)
    {
        $compilation = Compilation::findOrFail($id);
        $products = $compilation->products()->paginate($request->limit ?? 10);

        return (new ProductPaginationResource($products));
    }
}
