<?php

namespace Modules\Admin\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Modules\Admin\Repositories\Interfaces\BasketItemRepositoryInterface;
use Modules\Basket\Models\BasketItem;

class BasketItemRepository implements BasketItemRepositoryInterface
{
    public function __construct(
        private BasketItem $model
    ) {}

    public function all(): Collection
    {
        return $this->model->all();
    }

    public function find(int $id): ?BasketItem
    {
        return $this->model->find($id);
    }

    public function delete(int $id): bool
    {
        return $this->model->destroy($id);
    }

    public function paginate(int $perPage = 10): LengthAwarePaginator
    {
        return $this->model->orderBy('created_at', 'desc')->paginate($perPage);
    }

    public function count(): int
    {
        return $this->model->count();
    }
}
