// SPDX-FileCopyrightText: Politik im Blick developers
// SPDX-FileCopyrightText: Wolfgang Silbermayr <wolfgang@silbermayr.at>
//
// SPDX-License-Identifier: AGPL-3.0-or-later OR EUPL-1.2

use pib_service_api_types::{Index, get::ResponseBody};

use crate::{Backend, Result};

impl Backend {
    pub(crate) async fn get<E: Into<pib_service_facade::Error>>(&self) -> Result<ResponseBody, E> {
        Ok(ResponseBody(Index {}))
    }
}

#[cfg(test)]
mod tests {
    use std::sync::Arc;

    use pib_service_api_permissions::MockPermissions;
    use pib_service_api_types::{Index, config::oidc::OidcConfig};
    use pib_service_facade::Service as _;
    use pib_service_test_utils::mock_inventory_with_provider;
    use pretty_assertions::assert_eq;

    use super::ResponseBody;
    use crate::Backend;

    #[tokio::test]
    async fn endpoint() {
        let (_inventory, provider) = mock_inventory_with_provider();
        let permissions = MockPermissions::new();
        let oidc = OidcConfig {
            issuer: "https://auth.example.com/".to_string(),
            client_id: "abcdef".to_string(),
            client_secret: "ghijkl".to_string(),
        };

        let backend = Backend::new(provider, Arc::new(permissions), oidc.clone(), None);

        let response = backend.handle_get().await.unwrap();

        assert_eq!(response, ResponseBody(Index {}));
    }
}
