<?php
/**
 * BookiFlex Cart Extension
 *
 * @package    BookiFlex
 * @subpackage Cart
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */


declare(strict_types=1);
namespace BookiFlex\Extensions\Cart\Repository;

use BookiFlex\Extensions\Cart\Model\CartItem;
use Cycle\ORM\Select\Repository;
use DateTimeImmutable;

defined( 'ABSPATH' ) || exit;

class CartItemRepository extends Repository
{
    /**
     * Find items by cart ID
     */
    public function findByCartId(int $cartId): array
    {
        return $this->select()
            ->where('cart_id', $cartId)
            ->orderBy('sort_order', 'ASC')
            ->orderBy('created_at', 'ASC')
            ->fetchAll();
    }

    /**
     * Find items by type
     */
    public function findByType(string $type): array
    {
        return $this->select()
            ->where('type', $type)
            ->load('cart')
            ->fetchAll();
    }
}
