// file: kb_lib/src/upstream_registry.rs

//! Public service facade for the upstream Git registry.
//!
//! The registry is intentionally read-only in this tranche and does not touch
//! SQLite. It only exposes discovery seeds and static upstream-derived metadata
//! for UI inspection and later corpus validation.

/// Read-only upstream registry service.
#[derive(Clone, Debug, Default)]
pub struct UpstreamRegistryService;

impl UpstreamRegistryService {
    /// Creates a new read-only upstream registry service.
    pub fn new() -> crate::UpstreamRegistryService {
        return crate::UpstreamRegistryService;
    }

    /// Returns every static registry entry.
    pub fn all_entries(&self) -> std::vec::Vec<crate::UpstreamRegistryEntryDto> {
        return crate::upstream_registry_match::upstream_registry_all_entries();
    }

    /// Searches the static registry with optional filters.
    pub fn search(
        &self,
        request: &crate::UpstreamRegistrySearchRequestDto,
    ) -> crate::UpstreamRegistrySearchResultDto {
        return crate::upstream_registry_match::upstream_registry_search(request);
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn service_returns_static_registry_entries() {
        let service = crate::UpstreamRegistryService::new();
        let entries = service.all_entries();
        assert!(!entries.is_empty());
    }

    #[test]
    fn service_search_preserves_normalized_request() {
        let service = crate::UpstreamRegistryService::new();
        let request = crate::UpstreamRegistrySearchRequestDto {
            decoder_code: Some("raydium_cpmm".to_string()),
            program_id: None,
            program_family: None,
            surface_kind: None,
            entry_kind: None,
            proof_status: None,
            limit: Some(10),
        };
        let result = service.search(&request);
        assert_eq!(result.request, request);
        assert!(!result.entries.is_empty());
    }
}
