<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class Niwa_AI_RAG_Fallback {
    private $providers = array();

    public function __construct( $providers = array() ) {
        $this->providers = $providers;
    }

    public function search( $query, $constraints = array(), $limit = 4 ) {
        foreach ( $this->providers as $provider ) {
            if ( ! ( $provider instanceof Niwa_AI_RAG_Provider_Interface ) ) {
                continue;
            }

            $results = $provider->search( $query, $constraints, $limit );
            if ( ! empty( $results ) ) {
                return array_slice( $results, 0, max( 1, intval( $limit ) ) );
            }
        }

        return array();
    }
}
