cal-core 0.2.158

Callable core lib
Documentation
use crate::{ConnectState, FlowState};
use cal_jambonz::shared::shared::SIPStatus;
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Formatter};
use crate::device::device::{Connector, EndpointDevice};
use crate::device::shared::{AiOptions, CallControl, RecordOptions, TranscribeOptions};

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Plugin {
    //todo MapBox info
    pub plugin: String,
    pub data: String,
    #[serde(default = "crate::device::shared::build_present")]
    pub present: String,
    #[serde(default = "crate::device::shared::build_country_code")]
    pub country_code: String,
    #[serde(default = "crate::device::shared::build_ring_time")]
    pub ring_time: u8,
    #[serde(default = "crate::device::shared::build_call_time")]
    pub max_call_time: u16,
    #[serde(default = "crate::device::shared::build_connect_to")]
    pub on_transfer: String,
    #[serde(default = "crate::device::shared::build_connect_to")]
    pub on_error: String,
    #[serde(default = "crate::device::shared::build_connect_to")]
    pub on_complete: String,
    #[serde(default = "crate::device::shared::build_connect_to")]
    pub on_busy: String,
    #[serde(default = "crate::device::shared::build_connect_to")]
    pub on_fail: String,
    #[serde(default = "crate::device::shared::build_connect_to")]
    pub on_no_answer: String,
    #[serde(default)]
    pub record_options: RecordOptions,
    #[serde(default)]
    pub transcribe_options: TranscribeOptions,
    #[serde(default)]
    pub ai_options: AiOptions,
    #[serde(default)]
    pub call_control: CallControl,
}

impl Connector for Plugin {
    fn get_connect_to(&mut self, state: &mut FlowState) -> ConnectState {
        match &state.get_dial_status() {
            Some(status) => match status {
                SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
                SIPStatus::RequestTerminated => ConnectState::no_answer(self.on_no_answer.as_str()),
                SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
                    ConnectState::busy(self.on_busy.as_str())
                }
                _ => ConnectState::fail(self.on_fail.as_str()),
            },
            None => ConnectState::dialling(),
        }
    }
}

impl EndpointDevice for Plugin {
    fn device_type_name(&self) -> &'static str {
        "Plugin"
    }

    fn supports_routing(&self) -> bool {
        true
    }
}

impl Debug for Plugin {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Plugin")
            .field("plugin", &self.plugin)
            .field("data", &self.data)
            .field("present", &self.present)
            .field("country_code", &self.country_code)
            .field("ring_time", &self.ring_time)
            .field("max_call_time", &self.max_call_time)
            .field("on_transfer", &self.on_transfer)
            .field("on_error", &self.on_error)
            .field("on_complete", &self.on_complete)
            .field("on_busy", &self.on_busy)
            .field("on_fail", &self.on_fail)
            .field("on_no_answer", &self.on_no_answer)
            .field("record_options", &self.record_options)
            .field("transcribe_options", &self.transcribe_options)
            .field("ai_options", &self.ai_options)
            .field("call_control", &self.call_control)
            .finish()
    }
}


#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MapBox {
    #[serde(default)]
    pub bounds: MapBoxBoundary,
    #[serde(default)]
    pub features: Vec<MapBoxFeature>,
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MapBoxBoundary {
    pub xmin: f32,
    pub ymin: f32,
    pub xmax: f32,
    pub ymax: f32,
}

impl Default for MapBoxBoundary {
    fn default() -> Self {
        Self {
            xmin: 0.00,
            ymin: 1.00,
            xmax: 0.01,
            ymax: 1.01,
        }
    }
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MapBoxFeature {
    pub id: String,
    #[serde(rename = "type")]
    pub feature_type: String,
    pub geometry: MapBoxGeometry,
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MapBoxGeometry {
    #[serde(rename = "type")]
    pub geometry_type: String,
    pub coordinates: Vec<Vec<(f32, f32)>>,
}