/*
 * asklyphe-common nats/searchservice.rs
 * - nats structs for the asklyphe engine
 *
 * Copyright (C) 2025 Real Microsoft, LLC
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

use serde::{Deserialize, Serialize};

pub const SEARCH_SERVICE: &str = "searchbot";
pub const SEARCH_REPLY_SERVICE: &str = "searchbotreply";

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchSrvcQuery {
    pub request: SearchSrvcRequest,
    /// if using comms::query_service, you don't need to set this
    pub replyto: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SearchSrvcRequest {
    SearchRequest(SearchRequest),
    SiteCountRequest,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SearchSrvcResponse {
    InvalidRequest,
    OtherError(String),
    SearchResponse(SearchResponse),
    SiteCountResponse(SiteCountResponse),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SiteCountResponse {
    pub count: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchRequest {
    pub query: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResult {
    pub url: String,
    pub relevance: f64,
    pub title: Option<String>,
    pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SearchResponse {
    pub results: Vec<SearchResult>,
    pub blocked: Vec<(String, String)>,
    pub pagerank_time_seconds: f64,
    pub total_query_seconds: f64,
    pub max_relevance: f64,
    pub exact_phrase_found: bool,
}