Skip to main content

hoist_core/
service.rs

1//! Service domain definitions for multi-provider support
2
3use serde::{Deserialize, Serialize};
4use std::fmt;
5
6/// The service domain a resource belongs to
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8#[serde(rename_all = "kebab-case")]
9pub enum ServiceDomain {
10    /// Azure AI Search resources
11    Search,
12    /// Microsoft Foundry resources
13    Foundry,
14}
15
16impl ServiceDomain {
17    /// Human-readable display name
18    pub fn display_name(&self) -> &'static str {
19        match self {
20            ServiceDomain::Search => "Azure AI Search",
21            ServiceDomain::Foundry => "Microsoft Foundry",
22        }
23    }
24
25    /// Top-level directory prefix for resources of this domain
26    pub fn directory_prefix(&self) -> &'static str {
27        match self {
28            ServiceDomain::Search => "search-resources",
29            ServiceDomain::Foundry => "foundry-resources",
30        }
31    }
32}
33
34impl fmt::Display for ServiceDomain {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        write!(f, "{}", self.display_name())
37    }
38}
39
40#[cfg(test)]
41mod tests {
42    use super::*;
43
44    #[test]
45    fn test_display_names() {
46        assert_eq!(ServiceDomain::Search.display_name(), "Azure AI Search");
47        assert_eq!(ServiceDomain::Foundry.display_name(), "Microsoft Foundry");
48    }
49
50    #[test]
51    fn test_directory_prefixes() {
52        assert_eq!(ServiceDomain::Search.directory_prefix(), "search-resources");
53        assert_eq!(
54            ServiceDomain::Foundry.directory_prefix(),
55            "foundry-resources"
56        );
57    }
58
59    #[test]
60    fn test_display_trait() {
61        assert_eq!(format!("{}", ServiceDomain::Search), "Azure AI Search");
62        assert_eq!(format!("{}", ServiceDomain::Foundry), "Microsoft Foundry");
63    }
64
65    #[test]
66    fn test_serde_roundtrip() {
67        let domain = ServiceDomain::Foundry;
68        let json = serde_json::to_string(&domain).unwrap();
69        assert_eq!(json, "\"foundry\"");
70        let back: ServiceDomain = serde_json::from_str(&json).unwrap();
71        assert_eq!(back, domain);
72    }
73
74    #[test]
75    fn test_serde_roundtrip_search() {
76        let domain = ServiceDomain::Search;
77        let json = serde_json::to_string(&domain).unwrap();
78        assert_eq!(json, "\"search\"");
79        let back: ServiceDomain = serde_json::from_str(&json).unwrap();
80        assert_eq!(back, domain);
81    }
82}