use super::PowerAutomateConfig;
use crate::io::api::webhooks::{CallbackDestination, CallbackResolver, CallbackTarget, ErrorKind, WebhookError};
use std::env;
#[derive(Clone, Debug)]
pub struct PowerAutomateCallbackResolver {
config: PowerAutomateConfig,
}
impl CallbackResolver for PowerAutomateCallbackResolver {
fn resolve(&self, name: &str) -> Result<CallbackDestination, WebhookError> {
match name == self.config.callback_destination {
| false => Err(WebhookError::new(ErrorKind::InvalidTarget, "Unknown PowerAutomate callback destination")),
| true => env::var(&self.config.variables.callback_url)
.map_err(|_| WebhookError::new(ErrorKind::InvalidTarget, "PowerAutomate callback URL is unavailable"))
.and_then(CallbackTarget::new)
.map(|target| CallbackDestination::new(target, Vec::new())),
}
}
}
impl PowerAutomateCallbackResolver {
pub fn new(config: PowerAutomateConfig) -> Self {
Self { config }
}
}