<?php

namespace App\Repositories\Eloquent;

use App\Models\HeroSlide;
use App\Repositories\Contracts\HeroSlideRepositoryInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Cache;

/**
 * @extends BaseRepository<HeroSlide>
 */
class HeroSlideRepository extends BaseRepository implements HeroSlideRepositoryInterface
{
    public function __construct(HeroSlide $model)
    {
        parent::__construct($model);
    }

    /**
     * @param  array<string, mixed>  $filters
     * @return LengthAwarePaginator<int, HeroSlide>
     */
    public function paginate(array $filters = [], int $perPage = 15): LengthAwarePaginator
    {
        return $this->model->newQuery()
            ->orderBy('order_index')
            ->paginate($perPage);
    }

    /**
     * @return Collection<int, HeroSlide>
     */
    public function active(): Collection
    {
        return Cache::remember('hero_slides', 3600, fn () => $this->model->newQuery()
            ->where('is_active', true)
            ->orderBy('order_index')
            ->get());
    }
}
