// Copyright (c) 2026 Kirky.X
//
// Licensed under the MIT License
// See LICENSE file in the project root for full license information.

//! PermissionProvider trait 单元测试

#[cfg(test)]
mod tests {
    use async_trait::async_trait;
    use dbnexus::permission::provider::{PermissionContext, PermissionDecision, PermissionProvider};

    #[test]
    fn test_provider_trait() {
        // 测试 trait 定义
        let _provider: Box<dyn PermissionProvider> = Box::new(TestProvider {});
    }

    struct TestProvider;

    #[async_trait]
    impl PermissionProvider for TestProvider {
        async fn check_permission(&self, _context: &PermissionContext) -> PermissionDecision {
            PermissionDecision::Allow
        }

        async fn get_allowed_resources(&self, _subject: &str) -> Vec<String> {
            vec!["*".to_string()]
        }

        async fn get_allowed_actions(&self, _subject: &str, _resource: &str) -> Vec<String> {
            vec![
                "SELECT".to_string(),
                "INSERT".to_string(),
                "UPDATE".to_string(),
                "DELETE".to_string(),
            ]
        }

        async fn refresh(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
            Ok(())
        }

        fn name(&self) -> &str {
            "test"
        }
    }
}
