// src/search/grpc.rs

use common::proto::komp_ac::search::{
    searcher_client::SearcherClient, SearchRequest, SearchResponse,
};
use tonic::transport::Channel;
use anyhow::Result;

/// Internal search gRPC wrapper
#[derive(Clone)]
pub struct SearchGrpc {
    client: SearcherClient<Channel>,
}

impl SearchGrpc {
    pub fn new(channel: Channel) -> Self {
        Self {
            client: SearcherClient::new(channel),
        }
    }

    pub async fn search_table(
        &mut self,
        table_name: String,
        query: String,
    ) -> Result<SearchResponse> {
        let request = tonic::Request::new(SearchRequest { table_name, query });
        let response = self.client.search_table(request).await?;
        Ok(response.into_inner())
    }
}
