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

declare(strict_types=1);

namespace BookiFlex\Core\Repository;

use BookiFlex\Core\Admin\CPT\RatePlan as RatePlanCPT;
use BookiFlex\Core\Contract\RatePlan\RatePlanRepositoryInterface;
use BookiFlex\Core\Model\RatePlan\RatePlan;
use Cycle\ORM\Iterator;

defined( 'ABSPATH' ) || exit;

class RatePlanRepository extends BaseCPTRepository implements RatePlanRepositoryInterface
{
    protected static string $postType = RatePlanCPT::POST_TYPE;
    protected static string $class    = RatePlan::class;

    public function findAllByCodes(array $codes): iterable
    {
        $data = $this->findRawData();
        $data = array_filter($data, fn ($ratePlan) => in_array($ratePlan['code'], $codes));

        return Iterator::createWithOrm($this->orm, static::$class, $data);
    }
}
